Results 1 to 8 of 8

Thread: how do i send an array value to another form?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    24

    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??

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    24

    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

  4. #4
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    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.

  5. #5
    Member
    Join Date
    Apr 2005
    Posts
    39

    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

  6. #6
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429

    Re: how do i send an array value to another form?

    Quote 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.

  7. #7
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: how do i send an array value to another form?

    VB Code:
    1. FORM2:
    2.  
    3. Public X
    4.  
    5. Private Sub Form_Load()
    6. form2.X=form1.X
    7. end sub
    8.  
    9. Private Sub Command1_Click()
    10. Me.Print x(0)
    11. End Sub

    Note I have added (0)
    Rob C

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    24

    Red face Re: how do i send an array value to another form?

    thank you all for your help~! i used some of the methods above and solved the problem!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width