Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
What is wrong with my array?
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 -- Message posted from http://www.ExcelForum.com |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
What is wrong with my array?
You have declared your array as dynamic and have to "Redim" it in your
routine before you add an element. -- Regards; Rob ------------------------------------------------------------------------ "BLB " wrote in message ... I have written the following code that gives a compiling error "subscript out of range". Where am I going wrong? It is happening in the FOR loop of the "GetName" procedure. What I am trying to do is get input from the user on how many people will be added to the spreadsheet. If for example, they enter 2, than an input box will pop up 2 times asking for the names of those people and will store those 2 names in the Name() array. I have tried 2 different loops, actually, and both are included in the code below. Neither one 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 are 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 are adding.", "Staff Name") n(i) = temp ctr = ctr + 1 Next i //////////////////////////////////////////////////////////////// End Sub Please Help. Thanks --- Message posted from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
What is wrong with my array?
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Sum + IF Array wrong sum | Excel Worksheet Functions | |||
Array gives wrong answer | Excel Discussion (Misc queries) | |||
What's wrong with my array formula | Excel Discussion (Misc queries) | |||
Please help - What am i doing wrong with this array? | Excel Programming | |||
whats wrong with my array? | Excel Programming |