ASP SELECT CASE and Database

ASP SELECT CASE and Database

am 30.03.2006 16:48:49 von Neil

Hi,

I've have obtained an example shopping cart. It has the following code,
each case is for a different product. This code works fine for these 5
items.

Select Case iItemID
Case 1 aParameters = Array("./images/shop_shirt.gif", "ASP 101
T-Shirt", "Brief details about ASP 101 T-Shirt", "15.00")
Case 2 aParameters = Array("./images/shop_kite.gif", "ASP 101
Kite", "Brief details about ASP 101 Kite" , "17.50")
Case 3 aParameters = Array("./images/shop_watch.gif", "ASP 101
Watch", "Brief details about ASP 101 Watch" , "35.00")
Case 4 aParameters = Array("./images/shop_pen.gif", "ASP 101
Pen", "Brief details about ASP 101 Pen" ,"5.00")
Case 5 aParameters = Array("./images/shop_plate.gif", "ASP 101
Plate", "Brief details about ASP 101 late" ,"7.00")
End Select

However I want to pull this information from a database, I have tried
the following but I keep receiving an error it looks as if it doesn't
like the DO WHILE within the SELECT CASE statement:

strCase = 1
Select Case iItemID
Case strCase
Do while NOT accessories.EOF
aParameters = Array("../images/" &
accessories.Fields.Item("ID").Value) & ".gif",
(accessories.Fields.Item("Title").Value),
(accessories.Fields.Item("Paragraph1").Value),(accessories.F ields.Item("Saleprice").Value))
accessories.MoveNext()
strCase = strCase + 1
Wend
End Select

The error is :

Microsoft VBScript compilation error '800a0400'

Expected statement

/sctest/copyshopping.asp, line 412

Wend

Can anyone suggest how I populated a SELECT CASE statement from a
database?

Hope that all makes

Thanks

Neil

Re: ASP SELECT CASE and Database

am 30.03.2006 17:36:16 von reb01501

Neil wrote:
> Hi,

>
> However I want to pull this information from a database, I have tried
> the following but I keep receiving an error
> it looks as if it doesn't
> like the DO WHILE within the SELECT CASE statement:
>
> strCase = 1
> Select Case iItemID
> Case strCase
> Do while NOT accessories.EOF
> aParameters = Array("../images/" &
> accessories.Fields.Item("ID").Value) & ".gif",
> (accessories.Fields.Item("Title").Value),
>
(accessories.Fields.Item("Paragraph1").Value),(accessories.F ields.Item("Sale
price").Value))
> accessories.MoveNext()
> strCase = strCase + 1
> Wend

Wend is the wrong keyword to use here. Loop is the correct keyword.

While ... Wend
Do [While|Until] ... Loop [While|Until]
For ... Next

The Do construct is preferred to the While ... Wend construct which is
deprecated.


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Re: ASP SELECT CASE and Database

am 30.03.2006 17:59:15 von Neil

Thanks alot, that's sorted it but another problem has popped up.

Thanks again!

Re: ASP SELECT CASE and Database

am 30.03.2006 18:04:05 von reb01501

Neil wrote:
> Thanks alot, that's sorted it but another problem has popped up.
>
We're waiting with breathless anticipation ... ;-)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

Re: ASP SELECT CASE and Database

am 30.03.2006 19:37:09 von mmcginty

"Bob Barrows [MVP]" wrote in message
news:uyITw%23AVGHA.5004@TK2MSFTNGP11.phx.gbl...
> Neil wrote:
>> Hi,
>
>>
>> However I want to pull this information from a database, I have tried
>> the following but I keep receiving an error
>> it looks as if it doesn't
>> like the DO WHILE within the SELECT CASE statement:
>>
>> strCase = 1
>> Select Case iItemID
>> Case strCase
>> Do while NOT accessories.EOF
>> aParameters = Array("../images/" &

You are also missing an open-paren above (since you enclosed each of the
args to the Array function in unnecessary parens.)

But besides that, you can't populate a case statement with a loop, *unless*
you build source for the whole logical construct dynamically, in a buffer,
and then Execute that buffer. e.g.,

buf = "Select Case iItemID" & vbCrLf
Do while NOT accessories.EOF
buf = buf & "Case " & strCase & vbCrLf & _
"aParameters = Array(""../images/""" & ...
...
Loop

buf = buf & "End Select" & vbCrLf

Execute buf


-Mark


>> accessories.Fields.Item("ID").Value) & ".gif",
>> (accessories.Fields.Item("Title").Value),
>>
> (accessories.Fields.Item("Paragraph1").Value),(accessories.F ields.Item("Sale
> price").Value))
>> accessories.MoveNext()
>> strCase = strCase + 1
>> Wend
>
> Wend is the wrong keyword to use here. Loop is the correct keyword.
>
> While ... Wend
> Do [While|Until] ... Loop [While|Until]
> For ... Next
>
> The Do construct is preferred to the While ... Wend construct which is
> deprecated.
>
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>

Re: ASP SELECT CASE and Database

am 05.04.2006 12:49:36 von Neil

OK, thanks mark. I'll try that.

Re: ASP SELECT CASE and Database

am 06.04.2006 11:36:26 von Neil

That worked I really appreciate all the help.

Re: ASP SELECT CASE and Database

am 06.04.2006 17:28:23 von mmcginty

"Neil" wrote in message
news:1144316186.271290.237890@g10g2000cwb.googlegroups.com.. .
> That worked I really appreciate all the help.

Glad to help! Note you'll want to that use that trick sparingly, and
comment it well; it's a little expensive, and difficult to read (if anyone
else ever needs to maintain this code.)

-Mark