Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
BLB BLB is offline
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
RWN RWN is offline
external usenet poster
 
Posts: 104
Default 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   Report Post  
Posted to microsoft.public.excel.programming
BLB BLB is offline
external usenet poster
 
Posts: 1
Default What is wrong with my array?

Just what I needed! Thanks Rob

--
Message posted from http://www.ExcelForum.com

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sum + IF Array wrong sum ATL_Gabriel Excel Worksheet Functions 2 January 30th 09 01:21 AM
Array gives wrong answer Shu of AZ Excel Discussion (Misc queries) 1 November 11th 06 07:03 PM
What's wrong with my array formula M.Siler Excel Discussion (Misc queries) 4 May 27th 05 09:19 PM
Please help - What am i doing wrong with this array? acunnold Excel Programming 2 May 21st 04 10:49 PM
whats wrong with my array? joshashcraft Excel Programming 2 September 9th 03 07:54 PM


All times are GMT +1. The time now is 05:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"