PDA

View Full Version : ASP: long select case statement


TexStar
10-27-2004, 01:35 PM
What would be the quickest way to find out the 36 different "true false" possible case statements below.

*There is six true false. (e.g. below)

Select Case LenTest
Case "True, False, False, False, False, False"

Thank you.

afterburn
10-27-2004, 01:58 PM
thats a string... and you already know the values... why use a select statement... and it what case would you have a structure like that...?????

TexStar
10-27-2004, 02:13 PM
Thanks for responding.

This is being used to test if a field has been left blank in a form when updating a database.

eRad
10-27-2004, 03:09 PM
instead of testing a giant string compilation of all the values, you can just test each part individually while you are updating the DB.

now if you are trying to prevent users from entering blank values, you should use some sort of validation... either serverside in VBscript or through javascript, your preference. just loop through your elements and flag (or alert) if you find a blank... otherwise submit.

if your fields in the DB do not require values, and you are simply worried about entering blank values as they might be invalid... then just construct your SQL string in a fashion that checks each part for nullity

if you could specify which of the cases is appropriate, i can give you some sample code

putts
10-27-2004, 03:28 PM
arrList = split(lenTest,", ")
if arrList[0] = "True" then
.....blah blah blah....
end if


That seems to me to be the best option for what you are seemingly trying to accomplish.

If it's a matter of every item needs to be true or false then you could always loop through the array to check each item.

TexStar
10-28-2004, 10:24 AM
The code is written like this:

PLEASE PROVIDE AN EASIER WAY.

Thanks in advance.

' Name textbox
If Len(Request.Form("Name")) > 0 then
LenTest = "True"
Else
LenTest = "False"
End if
' Type textbox
If Len(Request.Form("Type")) > 0 Then
LenTest = LenTest & ", True"
Else
LenTest = LenTest & ", False"
End if
' Amount textbox
If Len(Request.Form("Amount")) > 0 Then
LenTest = LenTest & ", True"
Else
LenTest = LenTest & ", False"
End if
' ProdID field
If Len(Request.Form("ProdID")) > 0 Then
LenTest = LenTest & ", True"
Else
LenTest = LenTest & ", False"
End if
' Code field
If Len(Request.Form("Code")) > 0 Then
LenTest = LenTest & ", True"
Else
LenTest = LenTest & ", False"
End if
' Expires field
If Len(Request.Form("Expires")) > 0 Then
LenTest = LenTest & ", True"
Else
LenTest = LenTest & ", False"
End if

Select Case LenTest
'True cases
Case "True, False, False, False, False, False"
SqlCmd = "UPDATE Discounts SET Name = '" & Request.Form("Name") & "' WHERE discID = " & Request("DiscID")
Case "True, True, False, False, False, False"
SqlCmd = "UPDATE Discounts SET Name = '" & Request.Form("Name") & "', Type = " & Request.Form("Type") & "WHERE discID = " & Request("DiscID")
Case "True, True, True, False, False, False"
SqlCmd = "UPDATE Discounts SET Name = '" & Request.Form("Name") & "', Type = " & Request.Form("Type") & "', Amount = " & Request.Form("Amount") & "WHERE discID = " & Request("DiscID")