Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 New to VB and need some help.
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Matt_872000




PostPosted: Mon May 23, 2005 2:15 pm   Post subject: New to VB and need some help.

I've been fooling around with VB because I am learning it in class. I have just one question, it may sound kind of goofy, and it may be really easy, but how do you use variables throughout all or some of the "forms" or windows? It would be a great help.
Sponsor
Sponsor
Sponsor
sponsor
GlobeTrotter




PostPosted: Mon May 23, 2005 3:40 pm   Post subject: (No subject)

One way is to create a module and inside the module declare the variables as such:

code:

Global stStringVariable as String
Global iIntegerVariable As Integer


or whatever variables you are using.

They should then become usable over multiple forms.[/code]
Matt_872000




PostPosted: Tue May 24, 2005 12:28 pm   Post subject: (No subject)

Call me a loser or noob or whatever you like, but I'm not quite sure what a module is....
Maverick




PostPosted: Tue May 24, 2005 3:43 pm   Post subject: (No subject)

Right click on form i believe, on the right hand side where it says Form1, Form2 etc. and click on Create module then enter those variables. Im not positive thats it because im at home and not able to make sure thats correct
GlobeTrotter




PostPosted: Tue May 24, 2005 4:12 pm   Post subject: (No subject)

Yes, that is how you create a module.
Matt_872000




PostPosted: Tue May 24, 2005 6:50 pm   Post subject: (No subject)

Thanx, I've made a module and it's declaring the variables. The only problem I have is when I assign a value to the variable and go to another form the variable doesn't have anything assigned to it... Is there someway were I can share the variables completely, throughout all of the forms?
GlobeTrotter




PostPosted: Tue May 24, 2005 8:15 pm   Post subject: (No subject)

If you declared the variables in the module as "Global VarName As whatever" it should work. The global makes it work over multiple forms. Are you sure you didn't declare it with a "Dim"?
Matt_872000




PostPosted: Wed May 25, 2005 12:08 pm   Post subject: (No subject)

Thanx alot. I tested it out individually and it works fine. It seems to be a problem with the program trying the get the variable from a text box. Here is my code involving the text box problem.

code:

In the module I have:

     Option Explicit
     Global ShipName As String

Then in the form called "OnePlayer":

     Option Explicit

     Private Sub Continue_Click()
          ShipName = ShipName.Text
          OnePlayer.Hide
          PlayerOneTravel.Show
     End Sub

Then in the form called "PlayerOneTravel":
     Option Explicit

     Private Sub Form_Load()
          WindowState = 2
          MsgBox (ShipName)
     End Sub
Sponsor
Sponsor
Sponsor
sponsor
GlobeTrotter




PostPosted: Wed May 25, 2005 4:26 pm   Post subject: (No subject)

That code looks fine. The only thing I can think of is this: Make sure you didn't declare ShipName anywhere else other than the module. If there are no other declarations of shipname, I'm not sure.
Matt_872000




PostPosted: Wed May 25, 2005 8:13 pm   Post subject: (No subject)

Hmmm... wierd. Well now I've run into another problem Razz. What is the list seperator i need to use if i want to use more than one variable in a command like "MsgBox(Variable)"? I know in Turing it is just "," but i have no idea what it is in VB.
GlobeTrotter




PostPosted: Wed May 25, 2005 8:18 pm   Post subject: (No subject)

Use an "&"

For example:

VisualBASIC:

Call MsgBox("Variable Name: " & VarName & " Variable two name: " & Var2Name)
betaflye




PostPosted: Mon May 30, 2005 8:51 am   Post subject: (No subject)

As for a shared variable, declare them using the Public statement rather than Dim, I believe.
Matt_872000




PostPosted: Wed Jun 01, 2005 12:26 pm   Post subject: (No subject)

I've solved my problem!! Very Happy I think it was because I didn't realise textbox names were considered variables... I'm not exactly sure, but it seemed when I changed the names of the textboxes and/or variables so that they were different it worked.
betaflye




PostPosted: Fri Jun 03, 2005 1:43 pm   Post subject: (No subject)

Sounds like you should review the scope of variables and other identifiers Smile
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 14 Posts ]
Jump to:   


Style:  
Search: