Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

instead of if then......

Posted on 2004-04-21
8
148 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
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…

856 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