devxlogo

Watch Out for “()” When Calling Subroutines

Watch Out for “()” When Calling Subroutines

To call a subroutine, you can use the Call statement or simply the name of the subroutine:

 	Call MyRoutine(firstParameter)	'Or	MyRoutine firstParameter

Notice you don’t include the parentheses in the second case. If you do, VB assumes you mean them as an operator. VB then determines the value of the parameter and passes the value to the routine, instead of passing the reference as expected. This is apparent in this example:

 	Call MyRoutine(Text1)

This passes the text-box control to MyRoutine. If you did it without the Call statement, VB evaluates Text1, which returns the default property value of the text box:

 	MyRoutine(Text1)

This default property is the text-box text. So, if the routine expects a control, you pass the text string from the control instead and will receive a type-mismatch error. To prevent this, always use the Call statement or don’t put parentheses in when calling a subroutine.

See also  Who are the Modern GPU Cloud Providers?
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist