|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Simple SELECT CASE QuestionDoes anyone know why this doesn't work:
Select Case X Case X or Y msgbox("hello world!") End Select It seems X or Y doesn't evaluate correctly (I think only the first 1/2 is evaluating). Instead, I believe the proper syntax is Case X, Y? Can anyone clarify why X or Y will compile but doesn't evaluate right? Spam Catcher wrote:
Show quoteHide quote > Does anyone know why this doesn't work: X or Y evaluates to a boolean True or False so unless X is True or both> > > Select Case X > Case X or Y > msgbox("hello world!") > End Select > > > It seems X or Y doesn't evaluate correctly (I think only the first 1/2 is > evaluating). > > Instead, I believe the proper syntax is Case X, Y? > > Can anyone clarify why X or Y will compile but doesn't evaluate right? X and Y are False the msgbox will not display If you want the equivalent of "If X = X or X = Y then..." you need Case X, Y Are X and Y booleans? What datatypes are they?
Additionally, if you don't have option strict on, A LOT of things will compile in VB.NET that will then either crash at runtime or have unexpected behavior. You need to always keep option strict on, and be careful of type safety. Show quoteHide quote "Spam Catcher" <spamhoneypot@rogers.com> wrote in message news:Xns980D871FCF2BBusenethoneypotrogers@127.0.0.1... > Does anyone know why this doesn't work: > > > Select Case X > Case X or Y > msgbox("hello world!") > End Select > > > It seems X or Y doesn't evaluate correctly (I think only the first 1/2 is > evaluating). > > Instead, I believe the proper syntax is Case X, Y? > > Can anyone clarify why X or Y will compile but doesn't evaluate right? "Marina Levit [MVP]" <someone@nospam.com> wrote in X and Y are integers - I suspect it is time for me to turn on option news:#nXAUIasGHA.1888@TK2MSFTNGP03.phx.gbl: > Are X and Y booleans? What datatypes are they? > > Additionally, if you don't have option strict on, A LOT of things will > compile in VB.NET that will then either crash at runtime or have > unexpected behavior. You need to always keep option strict on, and be > careful of type safety. strict... : ) > Does anyone know why this doesn't work: You could do the following:> > Select Case X > Case X or Y > msgbox("hello world!") > End Select > It seems X or Y doesn't evaluate correctly (I think only the first 1/2 > is evaluating). > > Instead, I believe the proper syntax is Case X, Y? > > Can anyone clarify why X or Y will compile but doesn't evaluate right? Select Case True Case X or Y MessageBox.Show("Hello World!") End Select I suspect however, you want the Case X, Y syntax which is the same as If X=X or Y=X then. Actually since X=X your sample should always evaluate to true regardless of the value of Y and show "hello world"). Instead, I would recommend the following: Select Case X Case Y, Z 'Do Something Case Else 'Do something else, or log an exception case? End Select Jim Wooley http://devauthority.com/blogs/jwooley Jim Wooley <jimNOSPAMwooley@hotmail.com> wrote in
Show quoteHide quote news:24f81e8f7c688c87f9ff6d0a16a@msnews.microsoft.com: Thank you - that is what I wanted : )> > I suspect however, you want the Case X, Y syntax which is the same as > If X=X or Y=X then. Actually since X=X your sample should always > evaluate to true regardless of the value of Y and show "hello world"). > Instead, I would recommend the following: > > Select Case X > Case Y, Z > 'Do Something > Case Else > 'Do something else, or log an exception case? > End Select "Spam Catcher" <spamhoneypot@rogers.com> schrieb: Yes, it is. In the sample above the binary OR of 'X' and 'Y' is computed, > Does anyone know why this doesn't work: > > Select Case X > Case X or Y > msgbox("hello world!") > End Select > > It seems X or Y doesn't evaluate correctly (I think only the first 1/2 is > evaluating). > > Instead, I believe the proper syntax is Case X, Y? and 'X' is not equal to 'X Or Y' if Y <> 0, for example. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
if then endif
Rank newbie question - Class or Function? how to speed up collections iteration VB Removing multiple items from a multi-select ListView Copy of class instance VStudio 2003 and 2005 on the same workstation? How to access and use Unmanaged Code Disposing unused sockets Event Handling in VB.Net + Late Binding |
|||||||||||||||||||||||