0

Say I have a string that looks like this...

Dim Value as String Value = "373, 273" 

My goal is to be able to use the VALUE string in a case statement...

So something along the lines of

Dim Number as integer Number = 273 Select Case Number Case Value Msgbox "Value is 273" Case else 'do nothing End select 

When I run this case statement - it does not read the VALUE (273) therefore it just goes to case else.

How can I use VALUE in my select case statement so that it recognizes the value of it???

6
  • And what's your question? Commented Feb 27, 2017 at 14:50
  • @ProGrammer updated Commented Feb 27, 2017 at 14:51
  • I'm not sure what you're trying to achieve here.. It seems like you're just trying to check if the Value contains Number, in which case you'd just use Value.Contains(Number.ToString()) Commented Feb 27, 2017 at 14:54
  • @ProGrammer Its tagged VB6 Commented Feb 27, 2017 at 14:56
  • @ProGrammer any idea how to do this in VB6? Commented Feb 27, 2017 at 14:57

1 Answer 1

1

Try this (untested):

Dim Number as Integer = 273 Dim Value = "373, 273" Dim numAsString = CStr(Number) If InStr(1, Value, numAsString) MsgBox("Value is " & numAsString) End If 
Sign up to request clarification or add additional context in comments.

7 Comments

I need this in a case statement :/ i dno how to go about that
What you're asking for doesn't make sense in a Select Case
well it does in this case. I'm trying to move away from harcoding values (272, 373) and rather have it table driven (storing numbers in VALUES string). So previously it was Case 273, 373. Now i'm trying to have the select case statement read the VALUE string - this way if i need to add another number - i don't have to publish the code, can simply update the DB
That is an entirely separate concern. Instead of Dim Value = "373, 273" you'll be getting the values from a query but it will still run through the same code in the exact same fashion.
Case 273, 373 isn't equivalent to Case "273, 373". In the first you're saying the case handles integers 273 and 373. In the second you're saying the case handles the string literal "273, 373". The best solution really depends on what you need to do depending on which value is match. If if it's just any value then maybe store the valid values in a collection and check if the number you're comparing is in the collection. If you need to do something different for each value then it's more likely you need to hard code it.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.