Results 1 to 5 of 5

Thread: Change Array variable from other class then it's 'creator' [RESOLVED]

  1. #1

    Thread Starter
    Hyperactive Member Bloged's Avatar
    Join Date
    May 2001
    Location
    Rotterdam, The Netherlands
    Posts
    330

    Change Array variable from other class then it's 'creator' [RESOLVED]

    Hi everyone,

    Another question by me !

    Next problem I encounter is this one:
    I create an array of an class, called Pion, like this:
    VB Code:
    1. Friend pioPion(30) As Pion

    And give it it's values like this:
    VB Code:
    1. Private Sub cmdTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTest.Click
    2.         Dim iLoop As Integer
    3.         Dim iX As Integer = 0
    4.         Dim iY As Integer = 0
    5.        
    6.         For iLoop = 0 To 29
    7.             Dim testPion As New Pion(iLoop, 0, "Blue")
    8.             pioPion(iLoop) = testPion
    9.             pioPion(iLoop).SetCoordinates(iX, iY)
    10.             If iX = 9 Then
    11.                 iY += 1
    12.                 iX = 0
    13.             Else
    14.                 iX += 1
    15.             End If
    16.         Next
    17. End Sub

    But i want this not in my frmMain Code but in a other class.... Is this possible? Hope you get what I mean... if not just ask for clarification!

    Grtz,

    Bloged
    Last edited by Bloged; Mar 16th, 2004 at 11:08 AM.

  2. #2
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    In your other class you could have a function like
    VB Code:
    1. Public Function LoopPion() As Pion()
    2.         Dim iLoop As Integer
    3.         Dim iX As Integer = 0
    4.         Dim iY As Integer = 0
    5.         Dim pioPion(30) as Pion
    6.  
    7.         For iLoop = 0 To 29
    8.             Dim testPion As New Pion(iLoop, 0, "Blue")
    9.             pioPion(iLoop) = testPion
    10.             pioPion(iLoop).SetCoordinates(iX, iY)
    11.             If iX = 9 Then
    12.                 iY += 1
    13.                 iX = 0
    14.             Else
    15.                 iX += 1
    16.             End If
    17.         Next
    18.  
    19.         Return pioPion
    20. End Function
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  3. #3

    Thread Starter
    Hyperactive Member Bloged's Avatar
    Join Date
    May 2001
    Location
    Rotterdam, The Netherlands
    Posts
    330
    Thanks pax for your answer, but iIf I'm not mistaken this will create the array in my other class and not on the frmMain....

    Or does this statement:
    VB Code:
    1. Return pioPion
    Sends back the complete array?

    Grtz,

    Bloged

  4. #4
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Yes, it will return the entire array.

    Another way could be to pass the array as a ByRef variable instead.

    VB Code:
    1. Public Sub LoopPion(ByRef pioArray() as Pion)
    2. '
    3. '
    4. '
    5. End Sub

    But all-in-all, you'll end up with the same result.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  5. #5

    Thread Starter
    Hyperactive Member Bloged's Avatar
    Join Date
    May 2001
    Location
    Rotterdam, The Netherlands
    Posts
    330
    Thanks pax... this seems like what I've been looking for... Will test it when I can!

    Grtz,

    Bloged

    Edit: Tested and works great! Thanks Again!
    Last edited by Bloged; Mar 16th, 2004 at 11:08 AM.

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