Newbie question... 'me' and other keywords

todonnell69

Member
Joined
Jun 8, 2005
Messages
15
Programming Experience
5-10
Given the following code...
Public Class Form1
Inherits System.Windows.Forms.Form
'Create array of vendor objects...
Dim maVendors(3) As Vendor
...

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Init vendor array...
maVendors(0) = New Vendor("Microsoft")
maVendors(1) = New Vendor("Mac")
maVendors(2) = New Vendor("HP")

'Bind the array to the textbox...
txtVendorName.DataBindings.Add("Text", maVendors, "VendorName")

End Sub

Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
Me.BindingContext(maVendors).Position -= 1
End Sub

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
Me.BindingContext(maVendors).Position += 1
End Sub
End Class

What does the 'me' refer to in the 2 button click event handlers?
Sorry, I know this is probably stupid, but I can't get the word 'BindingContext' to enumerate for any of the controls.
TIA!
 
i can't guess what you really want to ask.....if you want to know what is 'ME'...'ME' actually refer the current object of class

it will be better if you explain your question more.....
 
As akhhttar explained, 'Me' refers to the current instance of the class.
In your code the class is named Form1 and the 'Me' keyword is used in that class, so Me refers to the instance of that class. You can actually delete the Me. and it may still work as long as there are no other object in your app with the same name. I often use 'Me' in order to get the drop down list of objects and methods for that class that the IDE provides.
 
Paszt said:
I often use 'Me' in order to get the drop down list of objects and methods for that class that the IDE provides.
...I guess what confuses me still is -why is it when I type 'me.', the IDE will enumerate the BindingContext property(and many others) but if I just type 'form1.', it will not list BindinContext or quite a few others. Is form1 not refering to an actual form at that point?
 
No... Me is the current INSTANCE of the form.... Form1 is actualy the class type.

If you had two copies of Form1 running around, each sue of the Me kw would refer to that specific instance.

Tg
 
sorry, but 1 more follow up question...
If the 'me' represents the current instance of the class, in this case since the the 'me' is in the button's click event, wouldn't the button be the current class and not the form?
 
no, no, no....
The button is an object... the form is the class. the code that is running is in the form, it jsut simply handles the event fired by the button.

Now, if it isn't confusing enough... if you were to build a class that inherits from the button, then any code in there (but NOT in the event handler) that uses me would refer to that instance of the button.

Tg
 
todonnell69 said:
sorry, but 1 more follow up question...
If the 'me' represents the current instance of the class, in this case since the the 'me' is in the button's click event, wouldn't the button be the current class and not the form?
Me always refers to the current instance of the class in which the code is written, regardless of what else that class contains.
 
Back
Top