Select... Case Array Question

  • Thread starter Thread starter BluDog
  • Start date Start date
B

BluDog

Hi

If i am using a Select... Case is there any way to have the elements
of an array tested within a case, for example:

Dim MyChar as Char
Select Case MyChar
Case "a"c, "b"c, "c"c
'Do Something
End Select


Would something like this be possible:

Dim MyChar as Char
Dim testChars() as Char = {"a"c, "b"c, "c"c}
Select Case MyChar
CasetestChars
'Do Something
End Select

cheers

Blu
 
BluDog said:
Would something like this be possible:

Dim MyChar as Char
Dim testChars() as Char = {"a"c, "b"c, "c"c}
Select Case MyChar
CasetestChars
'Do Something
End Select

cheers

Blu

Nope. Whatever follows "Case" needs to be something the compiler can
resolve, i.e. a const, enum or literal value. A variable won't git it since
that is a runtime value. (there is probably a more technically correct way
to say that!)

Best Regards,

Andy
 
Andy Becker said:
Nope. Whatever follows "Case" needs to be something the compiler can
resolve, i.e. a const, enum or literal value. A variable won't git it since
that is a runtime value. (there is probably a more technically correct way
to say that!)

I tried this today but couldn't make it work:
(pseudo code, don't know if syntax is correct

Select Case Messagebox.Show("message",,DialogButtonsOKYesNo)
Case DialogButtonYes
code
Case DialogbuttonNo
code
End Case

Can anyone explain why that doesn't work?
 
Ricky,

I do not know why it is not working, this code works for me.

Select Case MessageBox.Show("messagebox", _
"", MessageBoxButtons.YesNo)
Case DialogResult.Yes
MessageBox.Show("Yes")
Case DialogResult.No
MessageBox.Show("No")
End Select

So I am curious why this works not for you?

Cor
 
Cor Ligthert said:
Ricky,

I do not know why it is not working, this code works for me.

Select Case MessageBox.Show("messagebox", _
"", MessageBoxButtons.YesNo)
Case DialogResult.Yes
MessageBox.Show("Yes")
Case DialogResult.No
MessageBox.Show("No")
End Select

So I am curious why this works not for you?

I'm not sure. I didn't fool with it long before just going with an If. I'll
try it again. Thanks.
 
* "Ricky W. Hunt said:
I tried this today but couldn't make it work:
(pseudo code, don't know if syntax is correct

Select Case Messagebox.Show("message",,DialogButtonsOKYesNo)
Case DialogButtonYes
'DialogResult.Yes'.

code
Case DialogbuttonNo

'DialogResult.No'.
 
Herfried K. Wagner said:
'DialogResult.Yes'.

That's what I had. It was probably some other syntax problem. I was in a
hurry and needed to get it out. I'll try it again tonight. Thanks.
 
Back
Top