Solved

instead of if then......

Posted on 2004-04-21
8
151 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Suggested Courses
Course of the Month9 days, 3 hours left to enroll

617 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