What is wrong with my array?

  • Thread starter Thread starter BLB
  • Start date Start date
B

BLB

I have written the following code that gives a compiling erro
"subscript out of range". Where am I going wrong?

It is happening in the FOR loop of the "GetName" procedure. What I a
trying to do is get input from the user on how many people will b
added to the spreadsheet. If for example, they enter 2, than an inpu
box will pop up 2 times asking for the names of those people and wil
store those 2 names in the Name() array. I have tried 2 differen
loops, actually, and both are included in the code below. Neither on
works.

Private Sub AddStaff_Click()

Dim qty As Integer
Dim Name() As String

Call GetQty(qty)
Call GetName(Name, qty)

End Sub
__________________________

Private Sub GetQty(q)
q = InputBox("How many people are you adding? ", "Staff Quantity")
End Sub
__________________________
Private Sub GetName(n, ByVal q)

Dim i as Variant
Dim temp As String
Dim ctr As Integer
ctr = 0

///////I HAVE TRIED THIS LOOP////////////
Do Until ctr = q
temp = InputBox("Please enter the name of the person you ar
adding.", "Staff Name")
n(ctr) = temp
ctr = ctr + 1
Loop
//////////////////////////////////////////////////

//////////AND I HAVE TRIED THIS LOOP/////////
For i = ctr To q
temp = InputBox("Please enter the name of the person you ar
adding.", "Staff Name")
n(i) = temp
ctr = ctr + 1
Next i
////////////////////////////////////////////////////////////////
End Sub

Please Help.

Thank
 
You have declared your array as dynamic and have to "Redim" it in your
routine before you add an element.
 
Back
Top