Be Aware, It’s Not C!

VB developers that program with C language might be confused by a feature in the language. Consider thiscode:

 Dim x As IntegerDim y As IntegerDim z As Integer     x = 10y = 20z = 0     ''''Assume function max returns the maximum ''''of  the twoif  (z = max(x, y)) > 0 then         Msgbox CStr(z)Else        Msgbox "How Come?"End if

In the code, you would expect the message box to display 20, as it would do in C. VB, however, comparesz with the RHS (right-hand side) even before the assignment, irrespective of the brackets. Be careful.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: