SELECT CASE problem

knockyo

Well-known member
Joined
Sep 20, 2006
Messages
78
Programming Experience
1-3
Hi All,

I'm doing the select case coding without hard code into the program, but do it in the alternate way. For example,

If i hard code everything inside the select case statement below, it work fine
VB.NET:
Select Case sNumber
 Case "123", "234"
   xxxxx
 Case "567", "890"
   xxxxx
End Select

BUT

If I try make it in the manual way, it not work already.
VB.NET:
If dr200.Length <> 0 Then
  For i = 0 To dr200.Length - 1
      If str200 = "" Then
            str200 = dr200(i)("sNumber")
      Else
            str200 = str200 & """, """ & dr200(i)("sNumber")
      End If
  Next
End If

Select Case sNumber
 Case str200
   xxxxx
 Case "567", "890"
   xxxxx
End Select
The above syntax will return exactly what I hard code above.

What i'm doing wrong the above syntax, please alter for me..

Thanks .... :(
 
If you are trying to say that str200 contains the string "123, 234" then that will not work, only when sNumber has the string value "123, 234" will that match.

To compare an array of values use just that, an array and the IndexOf method.
 
VB.NET:
Select Case sNumber
 Case str200
   xxxxx
 Case "567", "890"
   xxxxx
End Select

so, how to change the str200 variable values same as hard code values? "123","234"
 
I'm not sure that that's possible. Can you just use an if/then instead?
VB.NET:
If str200.IndexOf("""" & sNumber & """") >= 0 Then
  xxxxx
ElseIf sNumber = "567" Or sNumber = "890" Then
  xxxxx
End If
 
so, how to change the str200 variable values same as hard code values?
You can't do that. As I said, if you need a variable to refer to multiple values declare it as an array.
VB.NET:
Dim items() As String = {"123", "456"}
If Array.IndexOf(items, "123") <> -1 Then MsgBox("voila.")
 
Back
Top