Microsoft KB Archive/34279

From BetaArchive Wiki
Knowledge Base

Cannot Pass More Than 21 Dynamic Array Elements to Subprogram

Article ID: 34279

Article Last Modified on 11/21/2006


  • Microsoft QuickBasic 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBasic 4.5 for MS-DOS
  • Microsoft BASIC Compiler 6.0
  • Microsoft BASIC Compiler 6.0b
  • Microsoft BASIC Professional Development System 7.0

This article was previously published under Q34279


Passing more than 20 individual elements of a dynamic array to a subprogram or function procedure will produce the compiler error "Too many arguments in function call." This limitation occurs for all types of dynamic arrays. Either the whole array should be passed, or each item should be copied to a temporary variable and then passed to the subprogram or function.


This limitation occurs because of special handling done for dynamic arrays. When a subprogram is called, there is no way of ensuring that the dynamic array will not move. Therefore, when individual array elements are passed by reference, each is copied into a temporary location. These temporary locations are passed to the routine and then reassigned to the array when the routine is exited. There is a limit of 20 temporary locations.

The following is a complete code example:

DECLARE SUB test2 (a1!, a2!, a3!, a4!, a5!, a6!, a7!, a8!, a9!,_
                   a10!, a11!, a12!, a13!, a14!, a15!, a16!, a17!,_
                   a18!, a19!, a20!, a21!)
x = 30
DIM a(x)
CALL test2(a(1), a(2), a(3), a(4), a(5), a(6), a(7), a(8), a(9),_
           a(10), a(11), a(12), a(13), a(14), a(15), a(16), a(17),_
           a(18), a(19), a(20), a(21))

SUB test2 (a1!, a2!, a3!, a4!, a5!, a6!, a7!, a8!, a9!, a10!, a11!,_
           a12!, a13!, a14!, a15!, a16!, a17!, a18!, a19!, a20!, a21!)

    PRINT "hello"


The following is the compiler output:

Microsoft (R) QuickBasic Compiler Version 4.00b
Copyright (C) Microsoft Corp. 1982-1988. All rights reserved.
 0053   0006  ...a(18),a(19),a(20),a(21))
                                   ^ Too many arguments in function call

43059 Bytes Available
37660 Bytes Free

    0 Warning Error(s)
    1 Severe  Error(s)

Additional query words: QuickBas BasicCom

Keywords: KB34279