Forum Moderators: open

Message Too Old, No Replies

case select working partially

vbscript case select not working

         

kokopoko

10:01 pm on Feb 3, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



I've got a long vbscript case select in ASP that partially works. The case is a string such as "disaster evaluation" and other strings like that. This case select is not updating the count correctly. Can you have a string with spaces as your case in a case select?

Code:
pop=finalanswersArray(n)
Response.Write ("pop is "&pop&"<br>")
select case pop
Case "agriculture/forestry management"
count1=count1+1
Case "defense related"
count2=count2+1
Case "disaster evaluation"
count3=count3+1
Case "education"
count4=count4+1
Case "engineering/ transportation"
count5=count5+1
Case "land management/land cover"
count6=count6+1
Case "mapping"
count7=count7+1
Case "resource exploration"
count8=count8+1
Case "scientific/environmental research"
count9=count9+1
Case "urban dynamics"
count10=count10+1
Case "other"
count11=count11+1
Case else
count12= count12+1
end select

Zaphod Beeblebrox

10:58 am on Feb 4, 2004 (gmt 0)

10+ Year Member



The only thing I can think of is case-sensitivity. Try using:
Select Case LCase(pop)and keep all the string in your Case lines in lowercase as well.

mattglet

12:08 pm on Feb 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ZB is right, case statements are case sensitive. also, can you provide some results as to why you think your case is not updating correctly? There might be something else we can spot with a little more detail.

-Matt

kokopoko

4:47 pm on Feb 4, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



I am including the for loop around that snippet of code and the output for it that shows why it's not working.

for n=0 to ubound(finalanswersArray)-1
pop=finalanswersArray(n)
Response.Write ("pop is "&pop&"<br>")
select case LCase(pop)
Case "agriculture/forestry management"
count1=count1+1
Case "defense related"
count2=count2+1
Case "disaster evaluation"
count3=count3+1
Case "education"
count4=count4+1
Case "engineering/ transportation"
count5=count5+1
Case "land management/land cover"
count6=count6+1
Case "mapping"
count7=count7+1
Case "resource exploration"
count8=count8+1
Case "scientific/environmental research"
count9=count9+1
Case "urban dynamics"
count10=count10+1
Case "other"
count11=count11+1
Case else
count12= count12+1
end select
next

Response.write(count1&","&count2&","&count3&"<"&count4&"<"&count5&"<"&count6&"<"&count7&"<"&count8&"<"&count9&"<"&count10&"<"&count11&"<"&count12)

And here is the output: 1,1,<<<<<1<<<<15

Every count should have at least a value of 1, but they are not. Also some should have a value of more than 1, but they are not.

I did try the lowercase and it did not make a difference.

wackal

8:54 pm on Feb 4, 2004 (gmt 0)

10+ Year Member



if you don't specify the variable value it defaults to 0.

For example:

count1 + 1 = 1 because count1 starts off as 0

Before the for next loop, give all count variables a starting value of 1

txbakers

10:05 pm on Feb 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, he's right. you need to initialize the variables outside of the for loop, because inside the loop they get reset each time.

Option Explicit is a good idea too, which forces you to declare the variables before you use them. It's a good safety, especially since so many of your variables are similar.

Zaphod Beeblebrox

12:40 pm on Feb 5, 2004 (gmt 0)

10+ Year Member



Also, as a means of debugging, write out the value of 'pop' in your Case Else, that way you know precisely which ones are wrong, and yo can see why.