Microsoft KB Archive/38374

= Must Initialize Toolbox-Routine Parameters; GetDirName Sample =

Article ID: 38374

Article Last Modified on 11/21/2006



This article was previously published under Q38374



SUMMARY
The first reference to a variable cannot be in a toolbox-library routine. All variables used with library routines must be explicitly initialized (assigned to a certain value) before you use them with a library statement. If this is not done, incorrect program behavior may occur, as shown in the example below.

QuickBASIC DOES NOT warn you about uninitialized variables passed to toolbox-library routines, thus you must remember to initialize them.

Note that QuickBASIC DOES warn you with a &quot;Type Mismatch&quot; message at run time if you pass the incorrect variable type (string, integer, single precision, or double precision) to a toolbox routine or to many calls of the ToolBox statement. The type-checking information for a toolbox-library routine is stored in that routine's MBLC resource in QuickBASIC. For the ToolBox statement, which is a special MBLC routine, the type-checking information is stored in the MBTS resource in QuickBASIC and can be modified.



MORE INFORMATION
GetDirName is a toolbox routine that returns the current folder path. Calling GetDirName with an uninitialized string variable appears to work, but afterwards, all other uninitialized string variables are improperly initialized to the pathname returned by GetDirName. The following program demonstrates the behavior in the QuickBASIC interpreter: cls ' x$=&quot;&quot;    ' Must add this line to correct the bad behavior. GetDirName 0, x$  print x$   print y$  ' y$ now incorrectly contains the same as x$   print z$  ' z$ now incorrectly contains the same as x$ The memory environment in the QuickBASIC interpreter is confused after running the above program, and you must Quit then restart QuickBASIC to eliminate problems. You must add the statement x$=&quot;&quot; to make the program work correctly.

The following is taken from Page 420 of the &quot;QuickBASIC for Macintosh: BASIC Language Reference&quot; manual:   &quot;E.2.3.1 Initializing Variables The first reference to a variable cannot be in a ToolBox statement. All variables used with library routines must be explicitly initialized (declared to be a certain value) before you use them with a library statement. This initialization requirement does not apply to array variables, since the elements of an array are automatically initialized to 0 when the array is dimensioned. However, arrays must be dimensioned or referenced in the source code before being referenced in a library call.&quot;

Additional query words: MQuickB

Keywords: KB38374

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.