|
-
Mar 11th, 2001, 03:22 PM
#1
Thread Starter
Member
I have an array within one form in my project containing no more than 60 entries which I need to use on another form in my project. I've tried using
frmInterface.<arrayname> = <stuff>
but that gives an error. Is there any way of referencing arrays on different forms? If so can somebody please let me know! 
TIA
BioS
-
Mar 11th, 2001, 03:24 PM
#2
PowerPoster
Here ya go: To use this, just add a public function to your destination form and pass the array as indicated below
Code:
Option Explicit
Dim intNum(1 To 5) As Integer
Private Sub Command1_Click()
Call Form2.PrintNum(intNum())
End Sub
Private Sub Form_Load()
Dim X As Integer
For X = 1 To 5
intNum(X) = X
Next
End Sub
Private Sub PrintNum(xArray() As Integer)
Dim var As Variant
For Each var In xArray
Print var
Next
End Sub
-
Mar 11th, 2001, 03:27 PM
#3
Fanatic Member
When declaring the array in the form, declare it as: "Public Array(20) As Integer" (or however you're array is constructed, just use Public), then you can just use it as frmInterface.Array(Item)...
-
Mar 11th, 2001, 03:28 PM
#4
PowerPoster
that will also work. I just avoid using public variables.
-
Mar 11th, 2001, 03:31 PM
#5
Thread Starter
Member
Thanks both... exactly what I was looking fer 
BioS
-
Mar 11th, 2001, 04:24 PM
#6
Thread Starter
Member
The public thing doesn't seem to work and I didn't really understand the top example!
I get a compile error :
'Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules'
Any ideas on getting round this?
TIA
BioS
-
Mar 11th, 2001, 04:27 PM
#7
you can't make arrays Public variables. The way you would get around that is to declare a Public variable as a Variant, then set that variable = to the array, but that's too much work for me, I'd go with Lethal's way...
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 11th, 2001, 04:38 PM
#8
Thread Starter
Member
Any chance of an explaination of Lethal's way? does all that code go on the same form? and what is .PrintNum?
BioS
-
Mar 11th, 2001, 04:43 PM
#9
PowerPoster
The code I posted is just supposed to give you an example of passing arrays through multiple forms. The PrintNum function would go into your other form where you want to pass the array.
-
Mar 11th, 2001, 04:43 PM
#10
sure...
Code:
Option Explicit
Dim intNum(1 To 5) As Integer
Private Sub Command1_Click()
Call Form2.PrintNum(intNum()) ' sends the entire array to the sub on form2 called PrintNum
End Sub
Private Sub Form_Load() 'loads the array up with values, obviously
Dim X As Integer
For X = 1 To 5
intNum(X) = X
Next
End Sub
'on Form2
Private Sub PrintNum(xArray() As Integer)'takes in an array as a parameter
Dim var As Variant
For Each var In xArray
Print var ' prints each item in the array on the form
Next
End Sub
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 11th, 2001, 04:44 PM
#11
damn!
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 11th, 2001, 04:45 PM
#12
PowerPoster
hehehe.....your gettin' quicker there blade...
-
Mar 11th, 2001, 04:50 PM
#13
Thread Starter
Member
Cheers guys... appreciate it 
BioS
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
|