Link to home
Start Free TrialLog in
Avatar of Frank Freese
Frank FreeseFlag for United States of America

asked on

Different sub statements

Experts,
In my learning VB when I create a button the following code is created:
 Private Sub Button1_Click(sender As System.Object, 
e As System.EventArgs) Handles Button1.Click
 End Sub

Open in new window

However, when I look at the exmaples from the book I'm using I see this
 Private Sub Button1_Click(ByVaL sender As System.Object,
 ByVal e As System.EventArgs) Handles Button1.Click
 End Sub

Open in new window

The book adds the ByVal. Do I need to change some default(s)?
ASKER CERTIFIED SOLUTION
Avatar of Michael Fowler
Michael Fowler
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Frank Freese

ASKER

ok...if I neded ByRef then would I need to include both ByValue and ByRef or just ByRef?
If you do not include ByVal it is assumed by the system. If you want to use ByRef then you need to specify it. You cannot add both. To specify ByRef you would use something like

Private Sub (ByRef myVariable as string)

Note - Understanding reference and value types can be very important, especially when dealing with objects

Here is good discussion
http://www.vbforums.com/archive/index.php/t-612831.html

The difference between value types and reference types, in the most basic form, is that value types hold their data directly, while reference types point to a location in memory, and the data is located in that memory.

Michael
thank you