Array Errors When Call Function in Other Module w/ No Declare (94833)



The information in this article applies to:

  • Microsoft Visual Basic for MS-DOS
  • Microsoft Basic Professional Development System for MS-DOS 7.1
  • Microsoft QuickBASIC 4.5

This article was previously published under Q94833

SUMMARY

If a function called in one module exists in a different module and the calling module does not contain a Declare statement for that function, you can get one of the following error messages:

  • Subscript out of range
  • Type mismatch
  • Array not defined
This is because without the Declare statement, Basic thinks that you are implicitly declaring an array. Because Basic defines 11 elements implicitly in an array, your program may pass over the function without producing an error message. This can happen if you pass one numeric argument between 0 and 10.

To work around this problem, put a Declare for each function in the module where the function is called.

MORE INFORMATION

This may be a problem when converting an application from Visual Basic for Windows to Visual Basic for MS-DOS. It may also be a problem when creating a program in a separate editor and then loading that program into the interpreter environment.

The above mentioned Basic products do not automatically put Declare statements in modules that call functions that exist in a different module, so you can get unexpected results. Basic thinks these Functions are actually arrays, therefore giving an error message or quietly passing by your lines of code.

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB94833