Problem with For...Loop

1. Junior Member
Join Date
Dec 1969
Posts
19

## Problem with For...Loop

Hi there,<BR><BR>Can anybody help me figure out what the problem is with this?<BR><BR>Dim iTotal <BR>Dim sChar <BR><BR>iTotal = 0 <BR>For 1 To Len(qty(i, 1)) <BR> sChar = Mid(qty(i, 1), 1, 1) <BR> iTotal = iTotal + CInt(sChar) <BR>Next <BR><BR>I am getting the following error:<BR><BR>Expected identifier <BR><BR>/functions.asp, line 337 <BR><BR>For 1 To Len(qty(i, 1))<BR>----^<BR><BR>Thanks!<BR><BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
497

## RE: Problem with For...Loop

2 things.... <BR>can&#039;t make sense of your qty(i,1) what is qty and where did &#039;i&#039; come from...<BR>second you are not using a variable name for you &#039;for loop&#039;<BR>ie For j = 1 to 100<BR><BR>sponge

3. Junior Member
Join Date
Dec 1969
Posts
19

## RE: Problem with For...Loop

Sorry about that, Sponge. I posted earlier and got that answer but can&#039;t get it to work. Here&#039;s my original post...<BR><BR>Hi there, <BR><BR>always a challenge. I have three different quantities that I need to add up: <BR><BR>qty=session("quantity") <BR>for i=lbound(qty) to ubound(qty) <BR>Response.Write qty(i,1) <BR>next <BR>end sub <BR><BR>The value of the response.write is 548. I need to be able to add 5+4+8. Is this possible? If so, could somebody please help me know how to split these up and add them together to = 17? Any thoughts or comments would be helpful. Thanks so much! <BR><BR>Bennie <BR><BR>Thanks, Sponge.<BR><BR>When I use the "j", I get the following error:<BR><BR>Microsoft VBScript runtime error &#039;800a0009&#039; <BR><BR>Subscript out of range: &#039;i&#039; <BR><BR>/functions.asp, line 337 <BR>

4. Senior Member
Join Date
Dec 1969
Posts
497

## RE: Problem with For...Loop

try<BR><BR>qty=session("quantity") <BR><BR>blah blah...<BR><BR>for i=lbound(qty) to ubound(qty) <BR>total=0 &#039;make an array for this variable if you want to store it<BR>Response.Write qty(i,1)<BR>for x = 0 to len(qty(i,1))-1<BR> total = total + int(mid(qty(i,1),x,1))<BR>next<BR>next <BR><BR>The other possibility is divide by 10s...<BR>ie int(548/100)=5; int(548-5*(100))/10 = 4...<BR>this only works if it is a known number of digits... plus it kinda stinks..use as last resort<BR><BR>sponge<BR>

5. Junior Member
Join Date
Dec 1969
Posts
19

## RE: Problem with For...Loop

Thanks again sponge. It doesn&#039;t like "mid". Here&#039;s the error:<BR><BR>Microsoft VBScript runtime error &#039;800a0005&#039; <BR><BR>Invalid procedure call or argument: &#039;Mid&#039; <BR><BR>/functions.asp, line 389 <BR><BR>

6. Senior Member
Join Date
Dec 1969
Posts
497

## RE: Problem with For...Loop

try changing x = 1 to len(qty(i,1))<BR><BR>for x = 1 to len(qty(i,1))<BR> total = total + int(mid(qty(i,1),x,1)) <BR>next <BR>

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•