|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Having trouble understanding how case statements actually work. I've read that if you've got too many if/else statements then you should really use case statements.
But how do you actually write the statement for something like this: Code:
dim strDelete
if Request.form("delPcode") <> "" then
table = "<b>Products</b>"
strDelete = Request.form("delPcode")
delSQL = "DELETE FROM products WHERE id IN (" & strDelete & ")"
else if Request.form("delAuth") <> "" then
table = "<b>Authors</b>"
strDelete = Request.form("delAuth")
delSQL = "DELETE FROM authors WHERE authorID IN (" & strDelete & ")"
else if Request.form("delSupp") <> "" then
table = "<b>Suppliers</b>"
strDelete = Request.form("delSupp")
delSQL = "DELETE FROM suppliers WHERE ID IN (" & strDelete & ")"
end if
end if
end if
|
|
#2
|
|||
|
|||
|
You can't use a select .. case in your example. There can only be one tested expression and it's only evaluated once. An simple example of select case:
Code:
<%
myStr = "b"
Select Case UCase(myStr)
Case "A"
'some code here if it was an A
Case "B"
response.write "Yep, it was a ""B"""
Case Else
'code in case nothing else matches
End Select
%>
|
|
#3
|
|||
|
|||
|
you cant use a select statement because you are comparing differect variables... like Doug said, with a select stmt you have to compare the SAME variable...
|
|
#4
|
|||
|
|||
|
Oh, OK. So the only way to code more complex conditional statements like that is to have lots of ifs and end ifs?
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > Case statements |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|