Link to home
Start Free TrialLog in
Avatar of bertino12
bertino12

asked on

Shorten this conditional Statement

Is there a way to convert this to a shorter condition with OR's? I tried and got flakey results.
If tb.Text = "" Then
      If tb.Name = "textbox1" Then
      ElseIf tb.Name = "textbox2" Then
      ElseIf tb.Name = "textbox3" Then
      Else
           tb.Text = "0"
      End If
      bool = False
End If

Open in new window

Avatar of mds-cos
mds-cos
Flag of United States of America image

I would personally use a CASE statement for this (structured programming background), but don't see anything wrong with what you are doing.  Why do you want to shorten it?

If tb.Text = "" Then
      SELECT CASE tb.Name
             CASE "textbox1"
                    ......
             CASE "textbox2"
                   ......
             CASE "textbox3"
                  .......
             CASE Else
                  tb.Text = "0"
      END SELECT
       bool = False
End If
ASKER CERTIFIED SOLUTION
Avatar of mds-cos
mds-cos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaufmed
What about:
If tb.Text = "" AndAlso (tb.Name = "textbox1" OrElse tb.Name = "textbox3" OrElse tb.Name = "textbox3") Then
    tb.Text = "0"
    bool = False
End If

Open in new window

Second one should be "textbox2". Sorry :\