Subject: 'expected then' VB script compilation error
Posted By: Adam H-W Post Date: 1/29/2004 11:37:44 AM
Hi there

I'm getting a compilation error and I'm not sure why. Here's the rogue code:

intTotalPrice = intTotalPrice + (intQuantity * intPrice)

Set rsPacking =  server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM PPack ORDER BY PPid DESC"

set rsPacking = con.execute(strSQL)

if rsPacking.EOF then

else

do while not rsPacking.EOF

intPP = 0

If intTotalPrice > rsPacking("Limit") where rsPacking("PPid") = 1 then
intPP = rsPacking("FixPrice")
elseif intTotalPrice rsPacking("Limit") where rsPacking("PPid") = 2 then
intPP = rsPacking("FixPrice")
else
intPP = rsPacking("FixPrice") where rsPacking("PPid") = 3
end if
rsPacking.movenext()
loop
end if


The error is on line:

If intTotalPrice > rsPacking("Limit") where rsPacking("PPid") = 1 then


The error reads:  Microsoft VBScript compilation error '800a03f9'

Expected 'Then'

Not sure how to get out of it?

Any help much appreciated.

thanks

Adam
Reply By: planoie Reply Date: 1/29/2004 3:54:11 PM
"where" is not a VBScript keyword.  It looks like you are trying to mix SQL into VBScript.  What are you trying to do with that set of If/ElseIf?

Peter
------------------------------------------------------
Work smarter, not harder.
Reply By: Adam H-W Reply Date: 1/30/2004 4:05:07 AM
Hi Peter,

thanks for your input.

What I'm trying to achieve is a set of conditions where if the total amount of the shopping basket is over 50 then postage and packing is 5; if the total amount of the shopping basket is between 30-50, then postage and packing is 3 and if the total amount of the shopping basket is less 20, then the postage and packing will cost 2.

All values are being read from a SQL db. It seems that I'm not doing it correctly. Do you know how I can remedy it?

many thanks

Adam
Reply By: planoie Reply Date: 1/30/2004 1:26:01 PM
Where do you want to do this test?  You could do it either in SQL or in VBScript.  What do you mean by this: where rsPacking("PPid") = 1
Is this some postage and packing ID that corresponds to the limits?

Peter
------------------------------------------------------
Work smarter, not harder.
Reply By: Adam H-W Reply Date: 1/30/2004 1:33:31 PM
Hi Peter

Yes, that's right it corresponds to the incremental auto number that sql creates.

I want it so that an administrator can change the values when he or she so desires, so I need it to be database driven really. How would I be able to do this in SQL?

thanks

Adam
Reply By: jrwlkn Reply Date: 1/30/2004 1:43:06 PM
Substitute and for where...from a syntax point that is what you are trying to acheive...however, that may not logically cover all your scenarios


As for the logic, you may want to consider a select case statment
that looks at the three values of ppid and runs a series of commands accordingly.  This will probably be easier than SQL


John

Reply By: planoie Reply Date: 1/30/2004 1:58:47 PM
Ok, I think I get what you are doing. You need to select the shipping cost in a tiered cost system.  Perhaps this will work...

strSQL = "SELECT MIN(FixPrice) WHERE Limit > " & intTotalPrice

This will give you the minimum fixed shipping cost of all the costs that correspond to limits that are larger than your total.
Reply By: planoie Reply Date: 1/30/2004 2:00:09 PM
And BTW, you only need to select a single row value for this.
No need to loop thru rows.

Plus the benefit of this is that you can add tiers to the database without changing the logic of it.

Peter
------------------------------------------------------
Work smarter, not harder.
Reply By: Adam H-W Reply Date: 1/31/2004 4:15:33 AM
Great, thanks for your input guys - I'll give what you said a shot.

Cheers

Adam

Go to topic 9168

Return to index page 958
Return to index page 957
Return to index page 956
Return to index page 955
Return to index page 954
Return to index page 953
Return to index page 952
Return to index page 951
Return to index page 950
Return to index page 949