|
-
Feb 16th, 2010, 01:27 PM
#1
Thread Starter
Member
-
Feb 16th, 2010, 02:45 PM
#2
Re: getting variables to function over multiple forms
Where are you declaring them?
If you declare them in a module, then you can use them as is anywhere.
If you declare them on a form, then to be used else where you need to preface them with the form name.
Example:
Code:
'in a module
Public Hack As String
'on a form
Hack = "Test"
'on form1
Public Hack As String
'on another form
Form1.Hack = "Test"
-
Feb 16th, 2010, 02:51 PM
#3
Re: getting variables to function over multiple forms
Cal
I'm not an expert on this, but basically arrays dimmed on
a Form (even using Public) still have a "scope" limited to
only that Form.
One way around this is to add a Module to your project
and dim the array as Public in the declaractions section
of the Module. For the time being, this is probably all that
you will have in your Module, but that's ok.
Others may have more ideas, but I hope this one gets
you started.
Spoo
-
Feb 16th, 2010, 02:53 PM
#4
Re: getting variables to function over multiple forms
 Originally Posted by Hack
If you declare them on a form, then to be used else where you need to preface them with the form name.
Hack ... will that work with arrays?
Spoo
-
Feb 16th, 2010, 03:02 PM
#5
Thread Starter
Member
Re: getting variables to function over multiple forms
thanks very much guys. Great help. Il try both ways and see wat works and post back.
cal
-
Feb 16th, 2010, 03:15 PM
#6
Re: getting variables to function over multiple forms
Cal
My humble guess is that Hack's idea will not work with arrays
.. that is, the one where one preceeds the array by the form name.
Of course, Hack never specifically suggested that it would
work with arrays... just to clarify, he was only talking about variables.
1. You can't dim an array as Public on a form
2. You can dim an array on a form -- as in Dim aaArray(5, 5) -- on
a form, but it can't be "seen" as an array on another form, even
if preceeded by the original Form's name
Spoo
Last edited by Spoo; Feb 16th, 2010 at 03:22 PM.
Reason: add sentence "Of course, Hack never ... "
-
Feb 16th, 2010, 03:33 PM
#7
Thread Starter
Member
Re: getting variables to function over multiple forms
Spoo
Could u tell me in code how to dim the array as public in a module? I tried doing this:
Code:
Private Sub user_numbers(ByRef lott() As String)
Public lott_num(3) As Integer
End Sub
It doesnt work when i try to call it in the next form it says "sub or function not defined"...should i call it in the general declerations part of the next form or have i done it wrong? I know this is a nooby thing to not know but im still learning this in school so bear with me
-
Feb 16th, 2010, 03:36 PM
#8
Re: getting variables to function over multiple forms
Cal
No Sub is needed.
In the Declaractions section of the module (ie, at the very top)
all you need is
Code:
Public lott_num(3) as Integer
Spoo
-
Feb 16th, 2010, 03:42 PM
#9
Thread Starter
Member
Re: getting variables to function over multiple forms
Spoo
when i did this it says "Compile error: constants, fixed-length strings, arrays, user defined types and Declare statements are not allowed as Public members of object modules."
This was the method i tried at the start and got this message.
-
Feb 16th, 2010, 03:50 PM
#10
Re: getting variables to function over multiple forms
 Originally Posted by calarexar
... when i did this it says "Compile error: constants, fixed-length strings, arrays, user defined types and Declare statements are not allowed as Public members of object modules."
This was the method i tried at the start and got this message.
They need to be declared in a bas module, not the form.
-
Feb 16th, 2010, 03:52 PM
#11
Thread Starter
Member
Re: getting variables to function over multiple forms
LaVolpe,
yeah, just worked that out and have done it, like literaly as soon as i got this post! Thanks guys, massive help!
Last edited by calarexar; Feb 17th, 2010 at 02:35 PM.
-
Feb 20th, 2010, 10:44 PM
#12
Hyperactive Member
Re: [RESOLVED] getting variables to function over multiple forms
Don't know about the OP calling themselves a newbie.
I never knew this about arrays in VB. Never actually tried to do it of course but surely you can pass them as an address like in C++. I am sure I have read here that you can do that with variables and an array is just a group of variables in memory.
A very interesting and informative thread. Many thanks to the OP for starting it and everybody who has contributed.
Last edited by AsmIscool; Feb 20th, 2010 at 11:23 PM.
Slower than a crippled Vista
More buggy than a fresh XP install
Look! Down the road, some 50 miles behind the drunken snail.
It's Ubuntu!
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
|