Solved

instead of if then......

Posted on 2004-04-21
8
147 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
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

831 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