Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Shorten this conditional Statement

Posted on 2009-05-01
4
Medium Priority
?
199 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:bertino12
  • 2
  • 2
4 Comments
 
LVL 14

Expert Comment

by:mds-cos
ID: 24281001
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
0
 
LVL 14

Accepted Solution

by:
mds-cos earned 2000 total points
ID: 24281071
Ummm....oops!  I may have misread the intent of your code....did you simply omit the code that would normally follow "THEN"?

If not, try this....

 If tb.Text = "" Then
      If tb.Name <> "textbox1" and tb.Name <> "textbox2" and tb.Name <> "textbox3" Then
           tb.Text = "0"
      End If
      bool = False
End If
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24281173
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

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24281180
Second one should be "textbox2". Sorry :\
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question