Re: Init. Multi-dimensional String Arrays VB vs. VBA

Tech-Archive recommends: Fix windows errors by optimizing your registry




"cushlomokree" <cushlomokree@xxxxxxxxxxxxxxxx> wrote in message
news:Onq01VXqIHA.3680@xxxxxxxxxxxxxxxxxxxxxxx
Hi,
I'm having a little syntax nightmare.
I am trying to initialize a small 2-dimensional string array in VBA 6.5
(Word 2003).
I'm using syntax that works OK in Visual Studio 2005 VB, but VBA keeps
giving me an error (Compiler error ...expected expression.)
Here's the code:

Dim bookends(,) As String = {{"(", ")"}, {"[", "]"}, _
{"{", "}"}, {"<", ">"}}

Can anyone shed some light on this?

Yes, you are working under the misapprehension that VB.NET is the same
language as VB. The language was substantially changed in the transition
from VB6 to VB.NET. (Take a look at http://classicvb.org/ if you want to
understand more about this.)

Essentially, you have to regard VB.NET and VBA as two completely different
languages. Even their Integers aren't the same!

In VBA, you can't dimension and initialise a string array in a single
statement. You need to separate the dimension and initialisation.

Dim bookends(3, 1) As String
bookends(0, 0) = "("
bookends(0, 1) = ")"
bookends(1, 0) = "["
bookends(1, 1) = "]"
bookends(2, 0) = "{"
bookends(2, 1) = "}"
bookends(3, 0) = "<"
bookends(3, 1) = ">"



--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup


.



Relevant Pages

  • Re: Init. Multi-dimensional String Arrays VB vs. VBA
    ... I thought VBA was a working subset of VB (without the ... As a macro language, ... I am trying to initialize a small 2-dimensional string array in VBA 6.5 ...
    (microsoft.public.word.vba.general)
  • Re: "Open Browser Window And Select A File"
    ... I haven't been able to do this in VBA yet. ... and separate each file name into an element of the string array, ... I have a code that opens a browser window and also record all the file ...
    (microsoft.public.excel.programming)
  • Init. Multi-dimensional String Arrays VB vs. VBA
    ... I'm having a little syntax nightmare. ... I am trying to initialize a small 2-dimensional string array in VBA 6.5 ... I'm using syntax that works OK in Visual Studio 2005 VB, ... giving me an error (Compiler error ...expected expression.) ...
    (microsoft.public.word.vba.general)
  • Array constants in VBA Module sheet
    ... I need to write a module containing 3 simple VBA functions to call from ... appears that you can only set simple names as constants - not array ... dummy routine in the module once from the spreadsheet to initialize all ... What I really don't want to do is to individually initialize all 4 x 25 ...
    (microsoft.public.mac.office.excel)
  • Re: userform in VBAProject.otm not working
    ... A UserForm doesn't know an Initialize event; ... Michael Bauer - MVP Outlook ... VBOffice Reporter for Data Analysis & Reporting ... When I run the form from VBA editor it is initialized and it works. ...
    (microsoft.public.outlook.program_vba)