?
Solved

Subscript out of range message

Posted on 2003-02-25
12
Medium Priority
?
336 Views
Last Modified: 2012-08-14
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....
0
Comment
Question by:ssaville24
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
12 Comments
 

Author Comment

by:ssaville24
ID: 8018708
Typo.  It's 6 lines instead of 5 lines...

<%
Dim z
z=6
%>
0
 
LVL 7

Expert Comment

by:chisholmd
ID: 8018752
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?







0
 
LVL 18

Expert Comment

by:mgfranz
ID: 8020447
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


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:chisholmd
ID: 8020627
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
0
 

Author Comment

by:ssaville24
ID: 8021137
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
%>
0
 
LVL 18

Expert Comment

by:mgfranz
ID: 8021251
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.
0
 
LVL 7

Expert Comment

by:chisholmd
ID: 8021355
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
0
 
LVL 15

Accepted Solution

by:
gladxml earned 400 total points
ID: 8021915
ssaville24,

MAybe Maybe you cna try this approach... using a dropdown and not the button... Also it is much more effecient if you will save the the data in a database... Becasue in your process the only action that you can do is to resubmit the form...

The error that you have occurs when you get data that is not on the array collection or the number that you wnat to get exceed the maximum number of the array collection..


Here is the code... Basically the form has a dynamic input... It is somewhat similar to what you want to accomplish...

====save this as ssaville24-b.asp

 <% Response.Buffer = "True"%>
<%

if request.form("form_ok") = "True" then
for y = 1 to request.form("User")

if request.form("EmpNo" & y)  <> "" then
      
      if request.form("EmpName" & y)  <> "" then

'you can put your saving of record here

            tmpEmployeeNo = request.form("EmpNo" & y)  & "<br>"
            tmpEmployeeName = request.form("EmpName" & y)
            
response.write tmpEmployeeNo
response.write tmpEmployeeName
      end if

end if

next

'do a resposnse.redirect to other page....

end if
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<script language="Javascript">
<!--
function Passthis()
{
document.activeform.form_ok.value = "False";
activeform.submit();
}
function Savethis()
{
document.activeform.form_ok.value = "True";
activeform.submit();
}

// -->
</script>
<table width="784" height="665" border="0" cellspacing="0" cellpadding="30" align="center">
  <tr>
      <td valign="top" bgcolor="ffffff">
          <form name="activeform" method="POST" action="ssaville24-b.asp">
            <input type="hidden" name="form_ok" value="False">
        <table width="600" border="0" cellspacing="0" cellpadding="0" align="center">

          <tr>
               <td width="31%" valign="top" align="center">
              <div align="center"></div>
            </td>

            <td valign="middle" width="69%">
                          <div align="center"></div>
            <div align="center"></div>
</td>
          </tr>
          <tr>
            <td colspan="2" valign="top">
              <div align="left"></div>
              <table width="600" border="0" cellspacing="0" cellpadding="0" align="center">
                <tr>
                  <td height="1" bgcolor="#333333"> <img src="images/3.gif" width="1" height="1"></td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
              <td colspan="2" valign="top">
                <p align="center"><br>
                </p>
               
              <table width=600 align="center" valign="top" cellpadding="0" bgcolor="#FFFFFF" cellspacing="1" border="0">
                <tr bgcolor="#333333" > 
                  <td align="left" colspan="3" class="h2" height="30">@</td>
                </tr>
                <tr bgcolor="#cccccc" > 
                  <td align="left" class="h2" height="30">@</td>
                  <td align="left" class="h2" height="30" colspan="2">You can
                    input up to 20 PC User. </td>
                </tr>
                <tr bgcolor="#cccccc" > 
                  <td align="left" class="h2" height="30">
                    <div align="left">:</div>
                  </td>
                  <td align="left" class="h2" height="30">Please select number
                    of PC user</td>
                  <td align="left" class="h2" height="30">
                          <!--
                    <select class="content" onchange="doSel(this)" name="User">
                      <%for i = 1 to 20%>
                      <option value="location.href='PC5.asp?PCuser=<%=i%>'" <%if cint(request.querystring("PCuser"))=i then response.write "selected"%>><%=i%></option>
                      <%next%>
                    </select>
                    <input type="hidden" name="UserNum" value="<%=request.querystring("PCuser")%>">
                              -->
                    <select class="content" onchange="Passthis()" name="User">
                      <%for i = 1 to 20%>
                      <option value="<%=i%>" <%if cint(request.form("User"))=i then response.write "selected"%>><%=i%></option>
                      <%next%>
                    </select>
                  </td>
                </tr>
                <tr bgcolor="#cccccc" > 
                  <td align="left" width="10%" class="h2" height="30">@</td>
                  <td class="content" height="30">@</td>
                  <td width="56%" class="content" height="30">@</td>
                </tr>
                <tr bgcolor="#cccccc" > 
                  <td align="left" width="10%" class="h2" height="30">@</td>
                  <td class="content" height="30">Employee Number</td>
                  <td width="56%" class="content" height="30">Employee Name</td>
                </tr>
                        <%if request.form("User") <> "" then                        
                        for x = 1 to request.form("User")%>
                <tr bgcolor="#cccccc" > 
                  <td align="left" width="10%" class="h2" height="30">
                    <div align="center"><%=x%></div>
                  </td>
                  <td class="content" height="30">
                    <input type="text" name="<%="EmpNo" & x%>" value="<%=request.form("EmpNo" & x)%>">
                  </td>
                  <td width="56%" class="content" height="30">
                    <input type="text" name="<%="EmpName" & x%>" size="45" value="<%=request.form("EmpName" & x)%>">
                  </td>
                </tr>
                <%next
                        else%>
                <tr bgcolor="#cccccc" > 
                  <td align="left" width="10%" class="h2" height="30">
                    <div align="center"><%="1"%></div>
                  </td>
                  <td class="content" height="30">
                    <input type="text" name="<%="EmpNo1"%>" value="<%=request.form("EmpNo1")%>">
                  </td>
                  <td width="56%" class="content" height="30">
                    <input type="text" name="<%="EmpName1"%>" size="45" value="<%=request.form("EmpName1")%>">
                  </td>
                </tr>
                        <%end if%>
                <tr bgcolor="#333333" > 
                  <td align="left" colspan="3" class="h2" height="30">
                    <div align="center"></div>
                  </td>
                </tr>
              </table>
                        <table width="90%" border="0" cellspacing="0" cellpadding="4" align="center">
                <tr>
                  <td>@</td>
                </tr>
              </table>


              <table width="66%" border="0" cellspacing="0" cellpadding="5" align="center">
                  <tr>
                    <td >
                      <div align="center">
                        <input type="Submit" name="SubmitP5" value="Save & Next" Onclick="Savethis();">
                      </div>
                      <div align="left"> </div>
                    </td>
                  </tr>
                </table>

            </td>
          </tr>

        </table>
       </form>
      </td>
    </tr>
  </table>


Hope this help...

Happy programming...


0
 

Author Comment

by:ssaville24
ID: 8021916
chisholmd

yes i understand it completely, but you confused me with the hidden input boxes idea.
0
 

Expert Comment

by:CleanupPing
ID: 9576863
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.
0
 
LVL 58

Expert Comment

by:Gary
ID: 9753856
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
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question