Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Complex IF THEN statements in VB6 [duplicate]

Tags:

vb6

Possible Duplicate:
Does VB6 short-circuit complex conditions?

I am curious about how IF statements are executed in VB6. For example if I have the statement

If x And y Then
    'execute some code
End If

Does the code move on if x is not true? Or does it go ahead and evaluate y even though there is no logical point?

Another example

If x Or y Then
    'execute some code
End If

Does the code continue and evaluate y if x is true?

EDIT: Is there a way to avoid nested IF statements if I want to evaluate very complex conditions and I don't want to waste CPU time?

like image 817
aserwin Avatar asked Dec 19 '25 00:12

aserwin


1 Answers

What you are describing is short circuiting logic, and VB6 doesn't have it...

For example, in VB.Net you might write

If x AndAlso y then...

In this case y is not tested if x turns out to be false.

In your VB6 example, you'll get a Object or With block variable not set error if you try something such as:

Dim x as Object
If Not x Is Nothing And x.y=1 Then

Since object x has not been instantiated.

like image 187
Jon Egerton Avatar answered Dec 20 '25 19:12

Jon Egerton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!