Link to home
Start Free TrialLog in
Avatar of ssaville24
ssaville24

asked on

Subscript out of range message

I'm new to ASP, and I need help with finding the values of the array. What I'm trying to do is have 5 lines for the users to enter in information of their sites, then if they need to add more sites, they can click a button to add another 5 lines keeping the 5 lines items they have already answered.  I keep getting this error:

Microsoft VBScript runtime (0x800A0009)
Subscript out of range: '[number: 0]'
On this line:
cCLcheck = arr_cCLcheck(x-1)

Here's my code....
 

<%
Dim z
z=5
%>

<%
Dim x, cCLcheck, cCPcheck, site_name, band_width
Dim arr_cCLcheck, arr_cCPcheck, arr_cSiteName
Dim arr_cBandWidth, z              

arr_cCLcheck = split(request.form("cCLcheck"), ", ")
arr_cCPcheck = split(request.form("cCPcheck"), ", ")
arr_cSiteName = split(request.form("site_name"), ", ")
arr_cBandWidth = split(request.form("band_width"), ", ")
                                             
For x = 1 to z
If (z > 6) And (x > 0 AND x <= (z-6)) Then
                                       
        cCLcheck = arr_cCLcheck(x-1)
        cCPcheck = arr_cCPcheck(x-1)
        site_name = arr_cSiteName(x-1)
        band_width = arr_cBandWidth(x-1)
                             
Else                                   cCLcheck = ""                         cCPcheck = ""
        site_name = ""
     band_width = ""
End If
%>
<tr>
<td><span style='font-size:10.0pt;font-family:Geneva, Arial, sans-serif'>
<INPUT type="checkbox" name="cCLcheck" value="ON"<%=checkedValue("cCLcheck")%>>CL
<br>
<INPUT type="checkbox" name="cCPcheck" value="ON"<%=checkedValue("cCPcheck")%>>CP
</span></td>
<td> <INPUT class=textfield type="text" name="site_name" value=<%=site_name%>></td>
<td> <INPUT class=textfield type="text" name="band_width" value=<%=band_width%>></td>
</td>
</tr>
<%
Next
%>
<tr>
<td colspan=5> <input class=textfield type="button" name="AddMore" value="Add More Sites" onClick="sendInfo(1);">
</td>
</tr>

Please help....
Avatar of ssaville24
ssaville24

ASKER

Typo.  It's 6 lines instead of 5 lines...

<%
Dim z
z=6
%>
What happens if the user doesn't select the checkbox for cCLcheck ?  Empty array will fail on arr_cCLcheck(0)

By offering a check box I assume that it is OK for a user to leave it unchecked.  un-checked checkbox don't return a name-value pair.  Its a big drag.

so you might end up with returned fields like this:

cCLcheck "on,on"
cCPcheck "on,on,on"
cSiteName "redsite,bluesite,oldsite,newsite"
cBandWidth "bg,little,trickle,na"

You need to find another way of tracking them.  I think what I have done in the past is made hidden fields for each checkbox the hidden fields value is the name of the associated checkbox. Then for each hidden field I check for the existance of the checkbox. No checkbox means unchecked.

<input type=checkbox name=chk1 value="on">
<input type=hidden name=hidchk value="chk1">

then:
for counter = 1 to request.form("hidcheck").count
  if request.form(request.form("hidchk")(counter)) <> "" then
   'Its checked
  else
   'its unchecked
  end if
next


Also I would try is instead of setting z to 5 set z = ubound(arr..) then do your loop as 0 to z.

Make sense?







Avatar of Mark Franz
Try this;

cCLcheck = arr_cCLcheck(x) -1

But there are some fundemental flaws in your code, first remember that the Array is going to start at "0" unless you set your Option Base = 1.

arr_cCLcheck = split(request.form("cCLcheck"), ", ")

So the first arr_cCLcheck() is going to be "0"

So if you really wanted to start at "0"
                                           
For x = 0 to 5 ' or z

If (z > 6) And (x > 0 AND x <= (z-6)) Then '??? what the?  z is already set to 5


Try this;

arr_cCLcheck = split(request.form("cCLcheck"), ", ")
arr_cCPcheck = split(request.form("cCPcheck"), ", ")
arr_cSiteName = split(request.form("site_name"), ", ")
arr_cBandWidth = split(request.form("band_width"), ", ")
                                           
For x = 0 to z
' What you really should do is UBound() the array unless you are sure it is going to be more than 6
If x => 0 AND (x <= z) Then
                                     
       cCLcheck = arr_cCLcheck(x)
       cCPcheck = arr_cCPcheck(x)
       site_name = arr_cSiteName(x)
       band_width = arr_cBandWidth(x)
                             
Else                                   cCLcheck = ""                         cCPcheck = ""
       site_name = ""
    band_width = ""
End If


mqfranz: I think you need a day off dude. I have seen good answers from you in the past but today your a little off.

The fellow was using:
   cCLcheck = arr_cCLcheck(x-1)
because he is doing a for..next from 1 to 6
which as you say should be 0 to 5. So his notiation is correct.

This:
cCLcheck = arr_cCLcheck(x) -1

would be like saying "on-1" which obviously doesn't make any sense.

Perhaps you should slow down a bit today so that you don't send people on wild goose chases.

dave
chisholmd

I have this function in my code to check for the value of the checkbox...

<%
Function checkedValue(bTemp)
     If len(request.form(bTemp)) > 0 Then
          checkedValue = " Checked"
     Else
          checkedValue = ""
     End If
End Function
%>
Sorry, didn't see the input type part... :-/

INPUT type="checkbox" name="cCLcheck" value="ON"<%=checkedValue("cCLcheck")%

I get on the Array bandwagon to easily.
ssaville24: understood.  

But did you understand what I was saying about unchecked checkboxes not returning a name/value pair?  What it means is that unless ALL the checkboxes of the same name are checked your resulting arrays will be different lengths, but your treating them as all the same length in your for next.

dave
ASKER CERTIFIED SOLUTION
Avatar of gladxml
gladxml

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
chisholmd

yes i understand it completely, but you confused me with the hidden input boxes idea.
ssaville24:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Answer by gladxml

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
GaryC123
EE Cleanup Volunteer