Results 1 to 5 of 5

Thread: Public Arrays...

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Public Arrays...

    Say if i had the following code...
    VB Code:
    1. 'This is in a module
    2. Public Word_Str() As String
    3.  
    4.  
    5. Public Sub Send_Words(Amount_Of_Words As Integer)
    6.  
    7. ReDim Word_Str(0 To Amount_Of_Words)
    8.  
    9. For I = 0 To Amount_Of_Words
    10.  
    11. Word_Str(I) = Get_Random_Word 'This is just a function that produces a
    12.                                               'random word of any length when called.
    13. Next I
    14.  
    15. End Sub

    Now if i call this sub from a form the data that i get back is null and there's only one array (just 0) in the actual array, but if i call it from the same module the code works fine. Also if i don't ReDim the array it works, but i can't have a variable array.

    Can any one help me make it so that i can still have the public array that it variable and not turning the sub into a function and so that i can read it from any other part of the project.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Public Arrays...

    1) Where have declared I?

    2) hence, are you using Option Explicit?

    3) How are you calling the function?

  3. #3
    Frenzied Member pnish's Avatar
    Join Date
    Aug 2002
    Location
    Tassie, Oz
    Posts
    1,918

    Re: Public Arrays...

    I just tried it using your code and it works fine.

    The form
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  
    5.     Dim i As Integer
    6.     Send_Words 50
    7.    
    8.     For i = 0 To 50
    9.         Debug.Print Word_Str(i)
    10.     Next i
    11.    
    12. End Sub
    and the module
    VB Code:
    1. Option Explicit
    2.  
    3. Public Word_Str() As String
    4.  
    5. Public Sub Send_Words(Amount_Of_Words As Integer)
    6.  
    7.     Dim i As Integer
    8.     ReDim Word_Str(0 To Amount_Of_Words)
    9.    
    10.     For i = 0 To Amount_Of_Words
    11.         Word_Str(i) = "fred" & CStr(i)
    12.     Next i
    13.  
    14. End Sub
    Pete

    No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Public Arrays...

    Oh, ok i'll go look else where for the problem, maybe i've Redimmed it some where else.
    Thanks.

  5. #5
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Public Arrays...

    Slyke,

    The problem seems to be in your Get_Random_Word routine, which of course you did not post.

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