Solved

instead of if then......

Posted on 2004-04-21
8
150 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
[X]
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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
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…

729 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