Computing.Net > Forums > Programming > access to variables, vb.net

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

access to variables, vb.net

Reply to Message Icon

Name: intrepid_dave
Date: June 28, 2005 at 07:49:53 Pacific
OS: xp pro
CPU/Ram: 3200+ barton
Comment:

Can any one tell where i put variables that can be accessed from both outside and insite a button

e.g i have,
--------------

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Saturday Results
Dim satStart As Double = ComboBox1.Text
Dim satFinish As Double = ComboBox2.Text
Dim satStartMins As Double = ComboBox3.Text
Dim satFinishMins As Double = ComboBox4.Text

End Sub
--------------------

where can i put these variables so that i can acces them from both outside and inside this sub?
Can anyone help?

Dave



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: June 28, 2005 at 08:10:36 Pacific
Reply:

Define them outside of any function the form you wish to use themin the General Delarations section of the form.

You can then use them anywhere in the form. If you wish to use them elsewhere in the project, define them as Public. They are Private by default and are only availabel while that module is active.

Stuart


0

Response Number 2
Name: intrepid_dave
Date: June 29, 2005 at 05:10:39 Pacific
Reply:

thanks, but I tried putting them outside any function but i get an error

"An error occurred creating the form. See Exception.InnerException for details. The error is: Object reference not set to an instance of an object."

I put this outside:
Dim sunStartHours As Double = ComboBox5.Text



0

Response Number 3
Name: StuartS
Date: June 29, 2005 at 06:53:11 Pacific
Reply:

You define the variable first outside the function.

Then allocate it a value within the function you want to use it.

Dim sunStartHours As Double

outside the function

sunStartHours = ComboBox5.Text

inside the function.

It is never good programming practice to both define a variable and allocate it a value both in the same statememnt. Although it can be done, it can lead to also of problems later if you want to change anything.

Stuart


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Batch File Directory List... Prime Number problem in j...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: access to variables, vb.net

c++.net to either VB.net or c# www.computing.net/answers/programming/cnet-to-either-vbnet-or-c/397.html

VB.NET; ADO and Excel 2000 www.computing.net/answers/programming/vbnet-ado-and-excel-2000/13687.html

data base connection to vb.net 2008 www.computing.net/answers/programming/data-base-connection-to-vbnet-2008/16948.html