Solved

instead of if then......

Posted on 2004-04-21
8
145 Views
Last Modified: 2010-05-02
ok
here goes


If Text1 = "red" or Text1 = "Green" or Text1 = "Blue" then
   Text2 = "Color"
End If

This wont work. I know it.:)

How can i do this using either Case or Else Statements?

a brief explanation of why it won't work and an example of both options would be appreciated...thanx in advance.



0
Comment
Question by:kkoser
8 Comments
 
LVL 19

Accepted Solution

by:
Shauli earned 125 total points
ID: 10878674
Select Case Text1.Text
     Case "red", "Green", "Blue"
          Text2 = "Color"
      Case Else
           'do the other stuff
End Select

S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10878757
OK. I tested your code, and.... it does work! The only thing I can think of is the text being case sensitive, so if you enter "green" instead of "Green" that it wont work. In such a case you can match both sides of the formula using LCASE function, as in:

If LCase(Text1) = "red" Or LCase(Text1) = "green" Or LCase(Text1) = "blue" Then
   Text2 = "Color"
End If


S
0
 
LVL 19

Expert Comment

by:Shauli
ID: 10878786
ps. Use the LCASE with the Select Case option as well :)

S
0
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10878866
I don't know exactly what you are trying to accomplish but if you always want the user to select a color you could use a combo box instead of a text box.  This would eliminate the need to check to see if a correct color has been entered.  
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Expert Comment

by:Nightma12
ID: 10879488
If Text1 = "red" then
   Text2 = "Color"
ElseIf Text1 = "Green" then
   Text2 = "Color"
Elseif Text1 = "Blue" then
   Text2 = "Color"
End If

thats how i would do it :)
0
 
LVL 1

Expert Comment

by:dracko_14
ID: 10880939
Greetings from the pearl of the orient!(",)

Shauli is right from his code you can do it this way:

Select Case Text1.Text

Case Trim(Lcase("red")), Trim(Lcase("Green")),Trim(Lcase( "Blue"))
          Text2 = "Color"
      Case Else
           'do the other stuff
End Select

*** The trim is to take of all trailng characters in the textbox
***(eg.space)

***I hope this would help (",)
0
 

Author Comment

by:kkoser
ID: 10915049
thanx to all of you for your input.
0
 
LVL 1

Expert Comment

by:dracko_14
ID: 10919287
ur welcome
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

759 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now