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("cCLche ck"), ", ")
arr_cCPcheck = split(request.form("cCPche ck"), ", ")
arr_cSiteName = split(request.form("site_n ame"), ", ")
arr_cBandWidth = split(request.form("band_w idth"), ", ")
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;fo nt-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....
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("cCLche
arr_cCPcheck = split(request.form("cCPche
arr_cSiteName = split(request.form("site_n
arr_cBandWidth = split(request.form("band_w
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;fo
<INPUT type="checkbox" name="cCLcheck" value="ON"<%=checkedValue(
<br>
<INPUT type="checkbox" name="cCPcheck" value="ON"<%=checkedValue(
</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....
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").c ount
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?
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,
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").c
if request.form(request.form(
'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?
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("cCLche ck"), ", ")
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("cCLche ck"), ", ")
arr_cCPcheck = split(request.form("cCPche ck"), ", ")
arr_cSiteName = split(request.form("site_n ame"), ", ")
arr_cBandWidth = split(request.form("band_w idth"), ", ")
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
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("cCLche
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("cCLche
arr_cCPcheck = split(request.form("cCPche
arr_cSiteName = split(request.form("site_n
arr_cBandWidth = split(request.form("band_w
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
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
ASKER
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
%>
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.
INPUT type="checkbox" name="cCLcheck" value="ON"<%=checkedValue(
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
chisholmd
yes i understand it completely, but you confused me with the hidden input boxes idea.
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.
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
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
ASKER
<%
Dim z
z=6
%>