|
-
Sep 23rd, 2005, 12:20 AM
#1
Thread Starter
Fanatic Member
Public Arrays...
Say if i had the following code...
VB Code:
'This is in a module
Public Word_Str() As String
Public Sub Send_Words(Amount_Of_Words As Integer)
ReDim Word_Str(0 To Amount_Of_Words)
For I = 0 To Amount_Of_Words
Word_Str(I) = Get_Random_Word 'This is just a function that produces a
'random word of any length when called.
Next I
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.
-
Sep 23rd, 2005, 12:25 AM
#2
Re: Public Arrays...
1) Where have declared I?
2) hence, are you using Option Explicit?
3) How are you calling the function?
-
Sep 23rd, 2005, 12:29 AM
#3
Re: Public Arrays...
I just tried it using your code and it works fine.
The form
VB Code:
Option Explicit
Private Sub Form_Load()
Dim i As Integer
Send_Words 50
For i = 0 To 50
Debug.Print Word_Str(i)
Next i
End Sub
and the module
VB Code:
Option Explicit
Public Word_Str() As String
Public Sub Send_Words(Amount_Of_Words As Integer)
Dim i As Integer
ReDim Word_Str(0 To Amount_Of_Words)
For i = 0 To Amount_Of_Words
Word_Str(i) = "fred" & CStr(i)
Next i
End Sub
Pete
No trees were harmed in the making of this post, however a large number of electrons were greatly inconvenienced.
-
Sep 23rd, 2005, 01:34 AM
#4
Thread Starter
Fanatic Member
Re: Public Arrays...
Oh, ok i'll go look else where for the problem, maybe i've Redimmed it some where else.
Thanks.
-
Sep 24th, 2005, 04:35 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|