Home All Groups Group Topic Archive Search About

There is no conditional And in VB?

Author
15 Nov 2006 8:27 AM
marcwentink
To my surprise Visual Studio 8 - VB evaluates C_B in

if C_A And C_B Then

And Hence if C_B is an expression that can only be validated if C_A is
true my code crashes. For example

If p_EdType <> "" And CLng(p_EdType) > 0 Then .....

There is no Conditional-And operator in Visual Basic?

I am presently working in VS 8 / .NET 2005

Marc Wentink

Author
15 Nov 2006 8:45 AM
Spam Catcher
marcwent***@hotmail.com wrote in news:1163579254.040009.272050
@i42g2000cwa.googlegroups.com:

> To my surprise Visual Studio 8 - VB evaluates C_B in
>
> if C_A And C_B Then
>
> And Hence if C_B is an expression that can only be validated if C_A is
> true my code crashes. For example
>
> If p_EdType <> "" And CLng(p_EdType) > 0 Then .....
>
> There is no Conditional-And operator in Visual Basic?

You could use:

AndAlso or OrElse
Author
15 Nov 2006 10:34 AM
M. Posseth
Huh ....:-|  surprise ? it is just using the wrong operator in the wrong
situation .

And  / Or are  are essentially bitwise operators , it is not possible to
support short-circuiting behaviors when doing logical AND and OR operations.

That is why we ( VB 2005 proggers )  have the Andalso / Orelse statements
who do use short circuit behavior so we may use both flavors when it is
apropriate to do so  ( bitwise or logical )

for more info :

http://www.panopticoncentral.net/archive/2003/08/18/179.aspx 


regards

Michel Posseth [MCP]



Show quoteHide quote
"marcwent***@hotmail.com" wrote:

> To my surprise Visual Studio 8 - VB evaluates C_B in
>
> if C_A And C_B Then
>
> And Hence if C_B is an expression that can only be validated if C_A is
> true my code crashes. For example
>
> If p_EdType <> "" And CLng(p_EdType) > 0 Then .....
>
> There is no Conditional-And operator in Visual Basic?
>
> I am presently working in VS 8 / .NET 2005
>
> Marc Wentink
>
>
Author
15 Nov 2006 4:47 PM
David Anton
VB short-circuiting logical operators: AndAlso,  OrElse
C# short-circuiting logical operators: &&, ||
VB non-short-circuiting logical operators: And, Or
C# non-short-circuiting logical operators: &, |
VB bitwise operators: And, Or
C# bitwise operators: &, |

Note that both VB and C# have non-short-circuiting logical operators.  Also
note that in both VB and C# some operators are overloaded to be both bitwise
and non-short-circuiting logical operators.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter


Show quoteHide quote
"marcwent***@hotmail.com" wrote:

> To my surprise Visual Studio 8 - VB evaluates C_B in
>
> if C_A And C_B Then
>
> And Hence if C_B is an expression that can only be validated if C_A is
> true my code crashes. For example
>
> If p_EdType <> "" And CLng(p_EdType) > 0 Then .....
>
> There is no Conditional-And operator in Visual Basic?
>
> I am presently working in VS 8 / .NET 2005
>
> Marc Wentink
>
>
Author
16 Nov 2006 9:47 AM
marcwentink
David Anton schreef:

> Note that both VB and C# have non-short-circuiting logical operators.

Right! Did not even came to my mind that they exisited! I never use
them in C++ or C#, and I thought And then should be &&....

Thanks!!
Author
15 Nov 2006 7:43 PM
Cor Ligthert [MVP]
Marc,

Do you mean with Visual Studio 8 the version 2003.

There was a Visual Studio 6 and after that the versions VS 2002, VS2003 and
VS2005.

Beside that there are language versions from VB named version 7, 7.1 and 8
but that is typical VB numbering and does not exist as a Microsoft product.

Cor

<marcwent***@hotmail.com> schreef in bericht
Show quoteHide quote
news:1163579254.040009.272050@i42g2000cwa.googlegroups.com...
> To my surprise Visual Studio 8 - VB evaluates C_B in
>
> if C_A And C_B Then
>
> And Hence if C_B is an expression that can only be validated if C_A is
> true my code crashes. For example
>
> If p_EdType <> "" And CLng(p_EdType) > 0 Then .....
>
> There is no Conditional-And operator in Visual Basic?
>
> I am presently working in VS 8 / .NET 2005
>
> Marc Wentink
>
Author
16 Nov 2006 6:30 AM
Michael D. Ober
VS 2005 is VS 8.  Take a look at the Visual Studio's Help About screen.  My
VS 2005 says its version 8.0.50727.42.  VB 8 (2005) has the shortcut
conditionals "AndAlso" and "OrElse".

Mike.

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:uXtrc4OCHHA.4764@TK2MSFTNGP03.phx.gbl...
> Marc,
>
> Do you mean with Visual Studio 8 the version 2003.
>
> There was a Visual Studio 6 and after that the versions VS 2002, VS2003
and
> VS2005.
>
> Beside that there are language versions from VB named version 7, 7.1 and 8
> but that is typical VB numbering and does not exist as a Microsoft
product.
>
> Cor
>
> <marcwent***@hotmail.com> schreef in bericht
> news:1163579254.040009.272050@i42g2000cwa.googlegroups.com...
> > To my surprise Visual Studio 8 - VB evaluates C_B in
> >
> > if C_A And C_B Then
> >
> > And Hence if C_B is an expression that can only be validated if C_A is
> > true my code crashes. For example
> >
> > If p_EdType <> "" And CLng(p_EdType) > 0 Then .....
> >
> > There is no Conditional-And operator in Visual Basic?
> >
> > I am presently working in VS 8 / .NET 2005
> >
> > Marc Wentink
> >
>
>
>
Author
16 Nov 2006 8:18 AM
marcwentink
Cor Ligthert [MVP] schreef:

> Do you mean with Visual Studio 8 the version 2003.

Well I am trying to port the app to .NET 2005, but it is originally in
..NET 2003.

If AndAlso is new in .NET 2005 I understand why it's not used.
Author
16 Nov 2006 3:28 PM
Tim Patrick
AndAlso and OrElse were introduced in Visual Basic .NET 2002 (VB7.0).

-----
Tim Patrick
Start-to-Finish Visual Basic 2005

Show quoteHide quote
> Cor Ligthert [MVP] schreef:
>
>> Do you mean with Visual Studio 8 the version 2003.
>>
> Well I am trying to port the app to .NET 2005, but it is originally in
> .NET 2003.
>
> If AndAlso is new in .NET 2005 I understand why it's not used.
>