0

This should be the easiest question all day!

All I want to see is how to condense some code.

Example:

If textbox.text = "0000" then
'do something
End If

If textbox.text = "0001" then
    'do something
    End If

What I want to do, is have that in 1 statement.

dwb
  • 475
  • 6
  • 31

2 Answers2

5

You can use the .Contains from an array of data. Here is a simple example.

Dim choices = {"0000","0001","0002"}  
If choices.Contains(textbox.text) Then
  'do something
End If
OneFineDay
  • 9,004
  • 3
  • 26
  • 37
  • If `do something` is the same thing, then that is one thing, but if `do something` is different based on the value of textbox.txt that is another thing... – Tony Hinkle Apr 30 '15 at 20:47
  • It was my fault with my wording. This is what I wanted tho. Thanks abunch! – dwb Apr 30 '15 at 20:55
2

If you want each condition to do something different:

If testbox.text = "0000" Then Do.Something Else If testbox.text = "0001" Then Do.SomethingDifferent

If you have multiple conditions to test to do the same thing:

If testbox.text = "0000" OR testbox.text = "0001" OR testbox.text = "0002" Then Do.Something

Tony Hinkle
  • 4,706
  • 7
  • 23
  • 35