There is no conditional And in VB?

  • Thread starter Thread starter marcwentink
  • Start date Start date
M

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
 
(e-mail address removed) wrote in @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
 
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]
 
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
 
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
 
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.
 
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.
 
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!!
 
Back
Top