473,394 Members | 1,845 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Need help understanding the Cursor

In the code below, clicking on the button ButtonChangeCursor changes the form's
cursor to a WaitCursor. Clicking the button ButtonRestoreCursor changes the
form's cursor back to its original cursor. For the reasons I explain below I
wouldn't expect this code to behave as it does, so why does it work?

Public Class Form1

Dim OldCursor As Cursor

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
OldCursor = Me.Cursor
End Sub

Private Sub ButtonChangeCursor_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButtonChangeCursor.Click
Me.Cursor = Cursors.WaitCursor
End Sub

Private Sub ButtonRestoreCursor_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButtonRestoreCursor.Click
Me.Cursor = OldCursor
End Sub

End Class

My confusion derives from the statement "OldCursor = Me.Cursor" in the Form's
Load event. After this statement executes, isn't the OldCursor variable
associated with the same object instance as the one that Me.Cursor is
associated with? That's what I would expect as the Dim statement for OldCursor
simply declares an object variable, it doesn't create a Cursor object. So if
OldCursor and Me.Cursor are associated with the same object, wouldn't any
changes to Me.Cursor affect OldCursor too? That's what I would expect, but
that's not what happens.


Nov 21 '05 #1
2 1545

Alex wrote:
In the code below, clicking on the button ButtonChangeCursor changes the form's cursor to a WaitCursor. Clicking the button ButtonRestoreCursor changes the form's cursor back to its original cursor. For the reasons I explain below I wouldn't expect this code to behave as it does, so why does it work?

Public Class Form1

Dim OldCursor As Cursor

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
OldCursor = Me.Cursor
End Sub

Private Sub ButtonChangeCursor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonChangeCursor.Click
Me.Cursor = Cursors.WaitCursor
End Sub

Private Sub ButtonRestoreCursor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonRestoreCursor.Click
Me.Cursor = OldCursor
End Sub

End Class

My confusion derives from the statement "OldCursor = Me.Cursor" in the Form's Load event. After this statement executes, isn't the OldCursor variable associated with the same object instance as the one that Me.Cursor is
associated with? That's what I would expect as the Dim statement for OldCursor simply declares an object variable, it doesn't create a Cursor object.

Right so far!
So if
OldCursor and Me.Cursor are associated with the same object, wouldn't any changes to Me.Cursor affect OldCursor too? That's what I would expect, but that's not what happens.


You are correct that any changes to *the object that they are both
pointing to* would affect them both. However, saying

Me.Cursor =

isn't altering a cursor object; it's point Me.Cursor (which, like
OldCursor, is an object variable) at a different cursor object. If
Cursors were mutable objects (they might well be, I dunno), and you did
something like:

Me.Cursor.SomeCursorProperty = SomeNewValue

then yes, you would find that now OldCursor.SomeCursorProperty also =
SomeNewValue. But that is not what you are doing when you say Me.Cursor
= SomeOtherCursorObject.

This kind of thing was maybe easier to understand when Set was still
around? :)
--
Larry Lard
Replies to group please

Nov 21 '05 #2
Thank you Larry. Your explanation makes perfect sense. I'm glad I asked.

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
1
by: waddley | last post by:
I have a client who wants to have Access ask to save changes anytime data is changed or added into the database. I'm not really an Access guy, I actually run their servers, but have been dropped...
1
by: jobs | last post by:
I'm trying to understand this and don't get it... I found some code that looks like it's going to work if I can make sense of how to position the div. The code displays a div with some data...
1
by: Lee | last post by:
Hi all, been playing with some code overriding WndProc to get information about mouse events. So far I've tried to capture when the left mouse button is pressed using the code below. Sometimes...
8
by: Patti | last post by:
I am new to SQL and have created a stored procedure for a .net web application. Unfortunately I had to use a cursor in the stored procedure, so it is taking several minutes to execute because it...
3
by: shorti | last post by:
db2 v 8.2 on AIX 5.3 I will try to explain as brief as I can what it is I need. I am building a function that will be called multiple times where I will need to return x amount of records each...
3
by: Greg Corradini | last post by:
Hello, I'm trying to perform a simple insert statement into a table called Parcel_Test (see code below). Yet, I get an error message that I've never seen before (see traceback below). I've tried...
1
by: AhmetYOL | last post by:
Hi all; How can i catch end of the cursor? CREATE OR REPLACE FUNCTION "public"."fnc_rapthsbordro" (bastar date, bittar date, basmuk integer, bitmuk integer, basmak varchar, bitmak varchar,...
4
by: CK | last post by:
Good Morning All, Can use use a variable for the FOR clause in a cursor? Example I have DECLARE @a varchar(50), @b varchar(50), @c varchar(50) DECLARE @sql varchar(255) DECLARE @x...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.