select case

select case array(a)

case is = 1 and txt1.text = 10

versus
 
case 1, and txt1.text = 10

What is the difference, (if any) between these two ways of using select case.

When do you use one over the other or are they interchangeable.

Are there benefits to using one over the other?


Thanks in advance,

jjjjjjj
LVL 1
jjjjjjjAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mcriderCommented:
You want to use:

   case is = 1 and txt1.text = 10

This is illegal:

   Case 1, And y = 1


Cheers!
0
RuchiCommented:
>>case is = 1 and txt1.text = 10

the first case statement tests if a is equal to 1. Keyword Is along with the comparison operator, =, >, <, sepcifies the range of values to test.

>>case 1, and txt1.text = 10

the second case statement checks if a is 1 or txt1.text = 10....

0
mcriderCommented:
Ruchi,

have you tried to do:

   case 1, and txt1.text = 10

You will get an error: "Compile error: Expexted: expression"


Cheers!
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

RuchiCommented:
mcrider: You're absolutely right.
0
mcriderCommented:
Also, when you are comparing text from a text box, you should be doing:

   case is = 1 and txt1.text = "10"

Not:

   case is = 1 and txt1.text = 10

In the second example, you are not comparing the correct type... txt1.text is a string type and 10 is an integer type...


Cheers!



0
jjjjjjjAuthor Commented:
Here is the code that I am using and it works, but I like the info the mcrider gave in a further comment about "10" as opposed to 10.  This does make sense:

Private Sub CmdDetPrice_Click()
'Clear any old data
TxtListPrice.Refresh
TxtDisPrice.Refresh
TxtTtlPrice.Refresh

'Prompts user for input errors and ends sub

If CboPartNum.Text = "" Or txtQty.Text = "" Then
MsgBox "A part number/quantity must be entered, please try again", vbInformation, "Error"
CboPartNum.SetFocus
Exit Sub
End If


'To set t as a value to count in the do statement, for locating item(r)
Dim t As Integer

t = r
    'To search out the array and find the entered text
   
   Do Until CboPartNum.Text = item(t)
        t = t - 1
   Loop

TxtListPrice.Text = Format(price(t), "currency")

' Finds discount value from record and qty entered; applies discount price.

Select Case discount(t)

    Case 1 And txtQty.Text > 100
        TxtDisPrice.Text = Format(price(t) * 0.9, "currency")
       
    Case 2 And txtQty.Text > 10 And txtQty.Text < 31
        TxtDisPrice.Text = Format(price(t) * 0.93, "currency")
       
    Case 2 And txtQty.Text > 30 And txtQty.Text < 51
        TxtDisPrice.Text = Format(price(t) * 0.91, "currency")
       
    Case 2 And txtQty.Text >= 51
        TxtDisPrice.Text = Format(price(t) * 0.88, "currency")
       
    Case 3 And txtQty.Text > 1000 And txtQty.Text < 10001
        TxtDisPrice.Text = Format(price(t) * 0.97, "currency")
       
    Case 3 And txtQty.Text > 10000
        TxtDisPrice.Text = Format(price(t) * 0.95, "currency")
               
    Case Else
        TxtDisPrice.Text = Format(price(t), "currency")
     
       
    End Select
    'Enters total price of purchase
   
     TxtTtlPrice.Text = Format((txtQty.Text * TxtDisPrice.Text), "currency")
0
jjjjjjjAuthor Commented:
Original question was wrong.  There should be no , in the code.

Sorry about the confusion.

jjjjjjj
0
sdland1Commented:
please visit http://lightning.prohosting.com/~shell123 and search the sniplets section for case youll see many examples
0
mcriderCommented:
In your question, removing the comma in the second example make both examples valid (including the string typing):

   case is = 1 and txt1.text = "10"

          versus
 
   case 1 and txt1.text = "10"

and both are identical and there are no difference.  This is the quote from the microsoft help page: "If not supplied, the Is keyword is automatically inserted."

So to answer your question they are completely interchangeable.


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mcriderCommented:
By the way, when you expressly use "Case Is"  You must specify an equality range... For example:


   Case Is = 8
   Case Is <> 8
   Case Is > 8
   Case Is => 8

You can not specify a range without the keyword "Is"


   Case is 9 'WILL GENERATE AN ERROR


If you Type in:


   Case > 9

The VB editor will automatically change the line to read:

   Case Is > 9


Cheers!
0
jjjjjjjAuthor Commented:
Thanks and sorry for the confusion.

jjjjjjj
0
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.