I would like to have one of my cases be a dynamic string because in my table these values changed partially except for the beginning code "2061" so how do I make my code do something similar to when I'm looking up in my query "... like '2061%' here is my code
Function GetResponse(val As String) As String
Select Case val
Case "2061"
Return "Opted Out"
Case "00"
Return ""
Case Else
Return "Other"
End Select
End Function
You can use the Like operator in VB.NET for this. Here I'm selecting the first case that matches True.
Function GetResponse(val As String) As String
Select Case True
Case val Like "2061*"
Return "Opted Out"
Case val = "00"
Return ""
Case Else
Return "Other"
End Select
End Function
In C# you would use an if statement to get the same functionality:
string GetResponse(string value)
{
if (value.StartsWith("2061"))
return "Opted Out";
else if (value == "00")
return "";
else
return "Other";
}
And in F#:
let GetResponse (value:string) =
match value with
| x when x.StartsWith("2061") -> "Opted Out"
| "00" -> ""
| _ -> "Other"
Note, I recommend using more descriptive function and variable names than this, but I don't know what context this code is in. "GetResponse" is vague, and doesn't indicate what the return values might mean. You might want to rename it as "GetUserOptedOutStatus" or something similar.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With