|
-
Feb 13th, 2009, 10:43 AM
#1
Thread Starter
Member
[RESOLVED] Variables
Is there a way to use a variable throughout an entire project. By declaring a variable as Public, it seems to be limited to the events associated with that particular form, not the project in total.
Also, I am running into problems trying to transfer the value of more thatn one variable to a module
Dim NumTeams as Integer
Dim NumBoards as Integer
NumTeams = Val(Textboix1.text)
NumBoards= Val(Textbox2.text)
Call Modsub(NumTeams,NumBoards)
That last line syntax workd with only one variable but not more than 1
-
Feb 13th, 2009, 11:09 AM
#2
Re: Variables
Thread moved from the FAQ forum, which is not the place to post your questions - VB6 assumed.
Public is what you want (Private is limited to the code file it is in), the problem you are having is that it is defined in a form - so outside of the form you need to specify the form too, eg:
This is needed because you can create multiple copies of the same form (and thus variables), and need to be able to determine which would be used.
As to calling the sub, what you showed should be fine, however if you leave out the Call keyword (or if it is a function, use the result) you need to remove the brackets.
-
Feb 13th, 2009, 01:33 PM
#3
Re: Variables
Use a module for Public variables. They will be accessible throughout the project.
Any sub or function will only accept the variables for which there are parameters. I.E., if your sub is
Code:
Public Sub ModSub(strThisString As String)
'code
End Sub
then it is only going to accept one variable because there is only one parameter in which to feed the variable.
If you need your sub to take two variables, then create two parameters in the sub.
-
Feb 13th, 2009, 01:36 PM
#4
Re: Variables
Variable Scope:
- A variable defined in a Sub or Function is only available to that Sub or Function
- A variable defined at the top of a form with Private (preferred) or Dim is available to all Subs and Functions in that form and that form only
- A variable defined as Private at the top of a code module is available to all Subs and Functions in that code module and that code module only
- A variable defined as Public (preferred) or Global at the top of a code module is available to all Subs and Functions in the app
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|