Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Visual Basic
Expertise: Beginner
Jan 28, 1999

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.
Deborah Kurata
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date