WD: Sharing a Globally Dimensioned Array Between (WordBasic)

Last reviewed: November 17, 1997
Article ID: Q77273
The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a
  • Word for the Macintosh, versions 6.0, 6.0.1, 6.0.1a

SUMMARY

In the Microsoft WordBasic macro language, you can create a dimensioned array, such as A(6,6), that is available throughout any macro.

MORE INFORMATION

To create a dimensioned array that is available globally to any WordBasic macro or subroutine, load the values into the array, open a text file, and write the contents of the array to the text file.

If a macro needs to access these values, it opens the text file, reads the values into the array, and manipulates the values as necessary. The macro writes the values back to the text file. The manipulated values are available again to the originating macro or any other WordBasic macro that requires them. The following sample WordBasic macro illustrates this process:

   Sub MAIN
      Dim a(6, 6)
      For x = 1 To 6
         For y = 1 To 6
            a(x, y) = y : Rem loading the array
         Next y
      Next x
      Open "test.dat" For Output As #2
         For x = 1 To 6
            For y = 1 To 6
               Print #2, a(x, y):REM Writing the array to a text file
            Next y
         Next x
      Close 2
      REM After opening a second macro, open the text file and read
      REM it into the array again. Manipulate the array at this
      REM point and write it back out to the text file.
      Open "TEST.DAT" For Input As #2
         For x = 1 To 6
            For y = 1 To 6
               Input #2, a(x, y) : Print "read " ; a(x, y)
            Next y
         Next x
      Close 2
   End Sub

Kbcategory: kbusage kbmacro KBSubcategory: kbwordvba


Additional query words: passing parameters winword2 6.0 6.0a
6.0c winword 6.0a 6.0c 7.0 word95 word6 1.0 winword 1.10 1.10a 2.0
2.0a macword 6.0.1 word7 2.0a-CD 2.0b 2.0c
Keywords : winword winword2 word6 word95
Version : 2.x 6.0 6.0a 6.0c 7.0 7.0a


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 17, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.