|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Help with global level variables..
In my Computer Science class, we are doing independant projects. For mine, I'm working on a text based Haunted House game. I want to be able to have users find a key in one form and be able to use it in another form. We never worked with global level variables in class so I'm not really sure how to do this. Here's sort of what I want:
When user's first try to enter this room, they can't because it's locked. Later on in the game, I want them to find a key and go back to the room and use it. Any help would be greatly appreciated.. thank you in advance. |
|
#2
|
||||
|
||||
|
Modules store global variables.
|
|
#3
|
|||
|
|||
|
Quote:
I'm not even sure what a module is... Help? |
|
#4
|
||||
|
||||
|
A module is basically a bit of code which is accessible by all of the forms in your project. To demonstrate how they work just add a module to your project. Go to Project -> Add Module, in the resulting "Add Module" window make sure the "New" tab is selected and the "module" icon is selected then click "Open".
You will now have a module added to your code called Module1. To demonstrate how to use it try declaring a variable in this module: Code:
Public var As String This variable called "var" is now accessible to all forms, to make sure of this, open up Form1 and click on the icon on the left of the three at the top of the project explorer window, to display the code for the form. On a blank line in this code type the letters va and hold down Ctrl and press the Space Bar, you will now see a list of commands that you may type: with the command "Val" being selected, if you press the down arrow twice you will see that your variable "var" is highlighted - to select this press "Tab". Because your variable appears on this list of commands it means that the current form can use it. To test it further, add another form to the project. Project -> Add Form -> Open, toggle to the code again and again type va and press Ctrl + Spacebar. Can you see your variable in the list? Now you can view or alter the value of your variable called "var" on any form!!! |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Help with global level variables.. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|