Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with for loop

Status
Not open for further replies.

foxphpbomb

Programmer
Apr 10, 2007
29
US
why does this not work:


Dim i
For i=1 to 4
UCII.AddItem UCII_rs,Array("RS","LITERAL","FORM","FORM","FORM"),Array("ID","1","Name","Price","radiobutton"),"increment"
Next

this is supposed to add an item to the cart 3 times.

when I do this:

UCII.AddItem UCII_rs,Array("RS","LITERAL","FORM","FORM","FORM"),Array("ID","1","Name","Price","radiobutton"),"increment"
UCII.AddItem UCII_rs,Array("RS","LITERAL","FORM","FORM","FORM"),Array("ID","1","Name","Price","radiobutton"),"increment"
UCII.AddItem UCII_rs,Array("RS","LITERAL","FORM","FORM","FORM"),Array("ID","1","Name","Price","radiobutton"),"increment"

it adds the item 3 times to the cart
 
did you meant to do this:

Dim i
For i=1 to 4
UCII.AddItem UCII_rs,Array("RS","LITERAL","FORM","FORM","FORM"),Array("ID",[red]i[/red],"Name","Price","radiobutton"),"increment"
Next

-DNG
 
do this then:

Dim i
For i=1 to 4
Response.Write UCII.AddItem UCII_rs,Array("RS","LITERAL","FORM","FORM","FORM"),Array("ID","1","Name","Price","radiobutton"),"increment"
Next

-DNG
 
I'm getting th following error:
Microsoft VBScript compilation error '800a0401'

Expected end of statement

with the carrot indicator after UCII.AddItem
 
I see what you're trying to do unfortunately it still does not work as it should.

It still adds the product only once as opposed to 3 times.

If i put:


Response.Write (UCII.AddItem(UCII_rs,Array("RS","LITERAL","FORM","FORM","FORM"),Array("ID","1","Name","Price","radiobutton"),"increment"))

Response.Write (UCII.AddItem(UCII_rs,Array("RS","LITERAL","FORM","FORM","FORM"),Array("ID","1","Name","Price","radiobutton"),"increment"))

in the for loop it adds the product 2 times instead of 6.

Could there be something inherent in the function UCII.AddItem that could be preventing the for loop from working?

here is the function:

function UCaddItem(adoRS, bindingTypes, bindingValues, alreadyInCart) {
bindingTypes = UC_VbToJsArray(bindingTypes);
bindingValues = UC_VbToJsArray(bindingValues);

var values = this.GetDataFromBindings(adoRS, bindingTypes, bindingValues);
var newRow = this.FindItem(bindingTypes, values);
if (newRow == -1) { // add new item
newRow = this.GetItemCount();
for (var iCol=0; iCol<this.numCols; iCol++) this.SC[iCol][newRow] = values[iCol];
this.ComputeItemTotals(newRow);
if(this.isLineItemDiscountValid()) this.SetDiscount( this.SC[this.GetIndexOfColName(this.DISCOUNTVALUE)][newRow], this.SC[this.GetIndexOfColName(this.DISCOUNTTYPE)][newRow], newRow);
}
else if (alreadyInCart == "increment") {
var indexQuantity = this.GetIndexOfColName(this.QUANTITY);
this.SC[indexQuantity][newRow] = parseInt(this.SC[indexQuantity][newRow]) + parseInt(values[indexQuantity]);
if (isNaN(this.SC[indexQuantity][newRow])) this.SC[indexQuantity][newRow] = 1;
this.ComputeItemTotals(newRow);
if(this.isLineItemDiscountValid()) this.UpdateDiscounts();
}
if(this.isLineItemTaxValid()) this.SetLineItemTax(newRow);
this.persist();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top