Does VB6 short-circuit complex conditions?

2020-04-02 07:19发布

问题:

Does VB6 short circuit conditional tests? That is to say, can I be sure a statement like...

If index <= array_size And array(index) > something Then

will never burst the array, whatever the value of index might happen to be?

回答1:

No, VB6's And and Or don't short-circuit (which is the reason why the short-circuit versions are called AndAlso and OrElse in VB.net — backward compatibility).



回答2:

In addition to the If/Then/Else/End If block, VB6 also supports a single-line If/Then/Else construct. You can nest these to achieve simple short-circuiting. However, since it's a single-line statement, you must perform your desired action on the same line as well. For example:

' From (no short-circuit)
If index <= array_size And array(index) > something Then

' To (short-circuit)
If index <= array_size Then If array(index) > something Then ...


回答3:

Select Case is a short circuit method if you can use it for your purpose.



标签: vb6