Hi - this might seem like a really dumb question, but I'm having a lot of trouble with a userform I'm creating.

I would like to get a list of strings from the user and store them into an array.

First, I would like to have the user define the size of the list. Next, an array will be created based on that size, and the user will be able to enter strings into a userform until the array is filled.

The way I'm doing it now is this: I call a first userform to get the size of the list from the user. Then, for however large that list is, I will call a second userform that many times and each time the user will enter a string and it is stored in an array.

My problem is: when the user enters the size of the list, an array of that size is created in a standard VBA module. In that same module, I call the second userform that many times and the user enters the string. However, to access this string I have to get it from the "OK_Button" event of this userform. I would like to store it in an array right there and then, but it cannot access the array, which is in the standard module. Niether can I declare the array in any event of this userform, because each time I call the userform from the standard module, the array is wiped out and redefined.

I did come upon a pseudo-solution by sending the string each time to a different procedure in the standard VBA module, and storing it into the array from there. However, to do this I had to make the array and the counter that keeps track of the array index both module-level variables so they could be accessed from this procedure. I really don't enjoy doing that because I'd rather have everything encapsulated, and I know that there has to be an easier way to do this.

Here is a description of what the code runs:

From my first userform that gets size of list:

Sub OK_Button_Click()

     Call Show_Second_Userform( First_Userform.List_Size.Value)

End Sub
From standard VBA module, a procedure that redims array size (the array is declared at the top of this module) and calls the second userform that many times:

Sub Show_Second_Userform(ByVal ListSize As Integer)

     ReDim ListArray(1 to ListSize)
 
     Dim i as integer
     For i = 1 to ListSize
          Second_Userform.Show
     Next i

End Sub
From the second userform that gets the string from the user and calls a procedure in the standard module which stores it:
Sub OK_Button_Click()

      Call Store_String( StringObject.String )

End Sub
From the standard VBA module, the procedure that gets this string and stores it into the array. Notice that "ListArray" and "i" were defined at the top of this module, so I am able to access them:
 
Sub Store_String( StringObject )

     ListArray(i) = StringObject

End Sub



Does anyone know if there is a way to do this using better encapsulation or a different method???

Thanks so much!

Dan