Results 1 to 7 of 7

Thread: passing arrays to subs/functions

  1. #1

    Thread Starter
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    Question passing arrays to subs/functions

    I tried to pass an array of strings to another sub (in another module) as byref value (byval is impossible) this dindn't work

    But if I do exactly the same but the 2 subs are in the same module , it does work

    could somebody help me?

  2. #2
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    It's OK with me..

  3. #3
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    can you give an example.....?

    by the way another way of doing it would be to join the elements of the array together with vbNullChar's then send it to your fuinction, then in the function split them again...that would solve your problem...thats how most of the API does it
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  4. #4

    Thread Starter
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    check attachment
    Attached Files Attached Files

  5. #5
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    calling a sub including the ( and ) surrounding its parameters forces by val which is why is shows you an error, remove the surrounding ( )'s and you are ok...

    also replace the (1) with (i) in the loop...

    i have highlighted the code that i have changed....

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim ar(0 To 10) As String
    5.     Dim i As Integer
    6.    
    7.     For i = 0 To 10
    8.         'ar(1) = i - INCORRECT
    9.         [b]ar(i) = i[/b] ' - CORRECT
    10.     Next i
    11.    
    12.     'Test (ar) - INCORRECT
    13.     [b]Test ar[/b] ' - CORRECT
    14. End Sub
    15.  
    16. Public Sub Test(a() As String)
    17.     Dim i   As Integer
    18.    
    19.     For i = 0 To 10
    20.         MsgBox a(i)
    21.     Next i
    22. End Sub

    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  6. #6

    Thread Starter
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    thanks, but i've allready sorted it out

  7. #7
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    can you tell us all how did you sort it out please?
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

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