String Checking

jnash

Well-known member
Joined
Oct 20, 2006
Messages
111
Programming Experience
Beginner
Hi there i want to check a string (cert) content's, i always thought it was .equals but i cant seem to implement it

this is my code:

VB.NET:
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] checkRating()[/SIZE]
[SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] cert[/SIZE]
[SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"Suitable for 12 years and over"[/COLOR][/SIZE]
[SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#800000]"12"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#008000]' The following is the only Case clause that evaluates to True.[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"Suitable for 15 years and over"[/COLOR][/SIZE]
[SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#800000]"15"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"Suitable for 18 years and over"[/COLOR][/SIZE]
[SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#800000]"18"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2]MsgBox([/SIZE][SIZE=2][COLOR=#800000]"Not Certified"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE]

Thanks Jon
 
try this:

VB.NET:
Public Sub checkRating()
Select Case cert
Case "Suitable for 12 years and over"
MsgBox("12")
Case "Suitable for 15 years and over"
MsgBox("15")
Case "Suitable for 18 years and over"
MsgBox("18")
Case Else
MsgBox("Not Certified")
End Select
End Sub
 
Last edited by a moderator:
its not working, it still comes up with "not certified" when cert is
"Suitable for 15 years and over"
 
Be certain that there are no extra space characters in the string. The Case statement always works; it must be that the string you are passing it does not *precisely* match what the Case statement says it must be to make '15' appear in the message box. Note that Case statements are case-sensitive as well. If you step through the program using F8, you will probably see that the 15 string is getting processed by Case Else. You just need to find out why.
 
i had to instances of cert, thank you very much for your help !!!
 
Last edited:
Back
Top