|
-
Apr 18th, 2005, 09:09 PM
#1
Thread Starter
Junior Member
how do i send an array value to another form?
i am trying to send a array value to form 1 to form 2
this is what i did
FORM1:
Public X
Private Sub Form_Load()
x=array(1,2,3)
end sub
FORM2:
Public X
Private Sub Form_Load()
form2.X=form1.X
end sub
Private Sub Command1_Click()
Me.Print x
End Sub
it gives me a subscript out of range error (run time error 9)
am i doing it wrong? or is there another way to do it??
-
Apr 18th, 2005, 09:19 PM
#2
Re: how do i send an array value to another form?
Do you want to pass just ONE value (as required), or the whole array?
Bruce.
-
Apr 18th, 2005, 09:24 PM
#3
Thread Starter
Junior Member
Re: how do i send an array value to another form?
1 value at a time
but i need to finish passing all the values
-
Apr 18th, 2005, 09:31 PM
#4
Re: how do i send an array value to another form?
One way would be to declare the Array() at Module level (ie placed in a Module) - giving it Public(Global) scope.
That way all the elements could be accessed from any Form.
Of course there are dissadvantages with this method!
Bruce.
-
Apr 18th, 2005, 09:42 PM
#5
Member
Re: how do i send an array value to another form?
Yeah! Yeah! Module use it and love it! If you want to send info back and forth to your gonna have to use it... luckily i have a half finished program of the module code here have fun
//Main Program!
intWorker = 5
If x = 0 Then
Call Storage(intgold, intlumber, intstone, intWorker, x) // <-- LOOK HERE
End If Calling module
//Module Being Called!
Public intlumber As Integer
Public intgold As Integer
Public intstone As Integer
Public intWorker As Integer
Public intLumberAddUp As Integer
Public intGoldAddUp As Integer
Public intStoneAddUp As Integer
Public intWorkerAddUp As Integer
Public intSBFarm As Integer
Public intSBHouse As Integer
Public intSBBarracks As Integer
Public intSBStonemine As Integer
Public intSBGoldmine As Integer
Public intSBTownhall As Integer
Public intBFarm As Integer
Public intBHouse As Integer
Public intBBarracks As Integer
Public intBStonemine As Integer
Public intBGoldmine As Integer
Public intBTownhall As Integer
Public intFarm As Integer
Public intHouse As Integer
Public intBarracks As Integer
Public intStoneMine As Integer
Public intGoldMine As Integer
Public intTownHall As Integer
Public Y As Integer
Public x As Integer
Option Explicit
Public Sub Storage(intgold, intlumber, intstone, intWorker, x As Integer)
If x = 0 Then ^
intgold = 500 |
intlumber = 750 |
intstone = 200 Sub being called LOOK HERE!
x = 1
End If
x = 1
intGoldAddUp = intgold
intLumberAddUp = intlumber
intStoneAddUp = intstone
intWorkerAddUp = intWorker
End Sub
Public Sub BuildingStorage(intBFarm, intBHouse, intBBarracks, intBStonemine, intBGoldmine, intBTownhall As Integer)
intSBFarm = intBFarm
intSBHouse = intBHouse
intSBBarracks = intBBarracks
intSBStonemine = intBStonemine
intSBGoldmine = intBGoldmine
intSBTownhall = intBTownhall
End Sub
Public Sub BuildingsBuilt()
If Y = 0 Then
intFarm = 1
intHouse = 1
intBarracks = 0
intStoneMine = 0
intGoldMine = 0
intTownHall = 1
Y = 1
End If
End Sub
-
Apr 18th, 2005, 09:48 PM
#6
Re: how do i send an array value to another form?
 Originally Posted by littleman001
If you want to send info back and forth to your gonna have to use it...
Thats not true......
Probably a better approach would be to use Get/Set Property on Form1!
(However, fo a few Public variables, I guess you can get by with the Module)
Bruce.
-
Apr 18th, 2005, 10:07 PM
#7
Fanatic Member
Re: how do i send an array value to another form?
VB Code:
FORM2:
Public X
Private Sub Form_Load()
form2.X=form1.X
end sub
Private Sub Command1_Click()
Me.Print x(0)
End Sub
Note I have added (0)
-
Apr 19th, 2005, 01:55 AM
#8
Thread Starter
Junior Member
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
|