Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select Case 1

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
0
0
US
Does select case not like <> ?

Example

Case is <> 2,3



It has taken me a while to make sense of what I hear at work involving computers. There is much talk of bugs and questions about Raid.
Therefore I have come to the logical conclusion that the only way to have a properly functioning computer is to regularly spray it with Raid bug killer.
 
It likes it just fine, if you use it correctly.

Case IS <> 2, IS <> 3
 
Tried it, not working.

It has taken me a while to make sense of what I hear at work involving computers. There is much talk of bugs and questions about Raid.
Therefore I have come to the logical conclusion that the only way to have a properly functioning computer is to regularly spray it with Raid bug killer.
 
For a single comparison:
[tt]Case Is <>2[/tt]

For a set of values slightly modify your Select Case:
[tt]y = 3
Select Case True
Case (y <> 2 And y <> 3 And y <> 4)
MsgBox "case 1"
Case y = 2, 3
MsgBox "case 2"
Case y = 4
MsgBox "case 3"
Case Else
MsgBox "other"
End Select[/tt]

combo
 
That didn't work either.

It has taken me a while to make sense of what I hear at work involving computers. There is much talk of bugs and questions about Raid.
Therefore I have come to the logical conclusion that the only way to have a properly functioning computer is to regularly spray it with Raid bug killer.
 

Code:
y = 3
Select Case y
   Case 2, 3
      ...[blue]
   Case Else
      ...[/blue]
End Select

But this is just a guess since you've never stated what you are trying to accomplish.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
I have a list of numbers that if it is a 2, 3 or 8 it gets filtered out.

Select for some reason isn't liking <> in any form but will accept Case 0, 1, 4, 5, 6, 7, 9

There are other places in the code I would like to use <> if possible.

It has taken me a while to make sense of what I hear at work involving computers. There is much talk of bugs and questions about Raid.
Therefore I have come to the logical conclusion that the only way to have a properly functioning computer is to regularly spray it with Raid bug killer.
 
Could you provide a sample of your code? The solution provided by combo works; I'm guessing you didn't implement it properly.

mint's response has a logic problem in that Case Is <> 2, Is <> 3 will always be true since each expression separated by the comma is treated as an OR condition. Thus, all values will be not equal to 2 OR not equal to 3.
 
This is the chunk giving me issues. It comes from a user form where the user puts in numbers separated by a comma. The first digit is a default example that starts with 8 so if its an 8 the user doesn't want that section of the user form.

If the number starts with a 2 or a 3 and is three digits total then the number is a valid number.

Also the test variables are generic variants that are used throughout the code as throw away's. They hold info for a short time and are cleaned out to be used again somewhere else.

For this code all variables are public.


Code:
3600:   TEST = Left(SEQUENCE_TextBox3, 1)

3700:   If TEST <> 8 Then

        ' Check for the left digit
3800:   Select Case TEST

                ' If the digit isn't a 2, 3 or 8 then something is wrong
                Case 0, 1, 4, 5, 6, 7, 9

                ' Tell the user whats going on
3900:           MsgBox "WARNING! Your panel number does not indicate the proper side", vbOKOnly + vbCritical, "Critical Error"

4000:           Exit Sub

4100:       Case Else

                ' Clear variables
4200:           TEST = Empty
4300:           TEST2 = Empty
4400:           TEST3 = Empty
4500:           I = 0

                ' Put everything in a variable so it can be chopped up
4600:           TEST = SEQUENCE_TextBox3

4700:           TEST4 = Len(SEQUENCE_TextBox3)

4800:           Do

                    ' Pull the first number with the comma
4900:               TEST2 = Right(TEST, 1)
                    Debug.Print "TEST2 " & TEST2
                
                    ' Increase the count by one
5000:               If TEST2 = "," Then TEST3 = TEST3 + 1
                    Debug.Print "TEST3 " & TEST3
                    
                    ' Shorten the length by one character
5100:               TEST4 = TEST4 - 1
                    Debug.Print "TEST4 " & TEST4
               
                    ' Will not have a comma before first 3 characters
5200:               If TEST4 <= 3 Then Exit Do
                    
                    ' Get the part of the string not used
5300:               TEST = Left(SEQUENCE_TextBox3, TEST4)
                    Debug.Print "TEST " & TEST
                
5400:           Loop
            
                ' Because the last number won't have a comma, need to increase the count
5500:           TEST3 = TEST3 + 1

It has taken me a while to make sense of what I hear at work involving computers. There is much talk of bugs and questions about Raid.
Therefore I have come to the logical conclusion that the only way to have a properly functioning computer is to regularly spray it with Raid bug killer.
 

You don't HAVE to provide the logic for some numbers. You may leave them without the 'action'.
You may try this:

Code:
Select Case y
  Case 2, 3, 8[green]
    'Nothing will happen here[/green]
  Case 0, 1, 4, 5, 6, 7, 9
    ...
  Case Else
    ...
End Select

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Thanks Andy

It has taken me a while to make sense of what I hear at work involving computers. There is much talk of bugs and questions about Raid.
Therefore I have come to the logical conclusion that the only way to have a properly functioning computer is to regularly spray it with Raid bug killer.
 
You are taking a value from a TEXT box. It's a string.

You are using LEFT() on that value. It's a string.

You are comparing it to numbers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top