Visual Basic carry a variable throughout an entire project
So I'm currently making program for my year 12 IPT assignment. It's a maths game for Year 4's and 5's.
I need to carry a variable throughout the entire project (across forms) so I can easily specify what level the user is playing and how many questions they want to answer etc..
The only way I would ever know how to do this would be to put different captions on labels and then read off the labels and I really don't want to have to do that. There's probably an advanced way that I've never heard of, but becuase my teacher doesn't know what he's doing my entire class is left to learn how to use VB by themselves and through books....so it would be great if I could get some help.
It's really just one word that I think I need though...like " public level as string" or "static level as string" something like that...
11 Months Ago
Related Article:Visual Basic has stopped working
is a solved Visual Basic 4 / 5 / 6 discussion thread by fx.eko that has 6 replies, was last updated 2 months ago and has been tagged with the keywords: visual, basic, 6, has, stopped, working.
Also, you have to put actual global variables in a Module, not in a Form. Your best bet is to alter your project to use Startup Object "Sub Main" rather than a form. To do that, create a module, put in a subroutine named "main" that loads your initial form, then put your globals in front of that. In the Project Explorer, right click on your project (top level of the project tree) and select "Project1 Properties...". Then select the module from the Startup Object drop-down in the General tab.
Just to get you going, here's some sample code (assumes a Module named Module1 and a form named Form1):
' This is in Module1
Public myString As String
myString = "Joe"
Dim myForm As Form
Set myForm = New Form1
' This is in Form1
Private Sub Form_Load()
Me.Caption = myString
Put this code in your form (General Declaration Section)
' Variable to hold 'VarValue' property value
Private refVarValue As String
Public Property Get VarValue() As String
VarValue = refVarValue
Public Property Let VarValue(ByVal strValue As String)
refVarValue = EnuValue
Then, when you call the form where you put the code above (ex, Form1)
Form1.VarValue = "Your String goes here"
'Then on form1 load event, put this code
Private Sub Form_Load()