Results 1 to 10 of 10

Thread: byref array

  1. #1

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

    Question byref array

    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
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Is your array declared as Public or Private?

  3. #3

    Thread Starter
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    private in my first sub, but when I pass it byref, It should be private, or else it is not realy passing it.

    check attachment. (This is not the real program but I just made it to test it)
    Attached Files Attached Files

  4. #4
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    I've found 2 things:
    For i = 0 To 10
    ar(1) = i
    Next i
    test (ar)

    1. It must be ar(i) = i - not ar(1) = i
    2. You are passing it wrong: instead of test (ar) type test ar()

    Also in your Test sub try not to hardcode any number, but instead use Ubound(a) for your loop.

    Roy

  5. #5

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

  6. #6

    Thread Starter
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    but what if test is a function ans is declared as:
    Code:
        public function test (a() as string) as boolean
            test = true
        end function
    Do I have to call my sub like this then
    Code:
    Dim boolean1 as Boolean
    Dim ar(0 To 10) As String
    boolean1 = test(ar())

  7. #7
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    You've got that right.

    ;-)

  8. #8

    Thread Starter
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    Originally posted by IROY55
    You've got that right.

    ;-)
    thanks for helping me

  9. #9
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808
    The only problem was the parenthesis. You had test (ar) and should be test ar. And if it were a funtion Ans = test(ar) is enough
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  10. #10

    Thread Starter
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    thanks
    I knew it was a problem with the parentheses (i've had the same porblem with C++) but I didn't really know how to do it

    But hat i do not understand is why it did work when it was all in 1 module

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