Home All Groups Group Topic Archive Search About

optional array problem

Author
12 Oct 2005 10:06 PM
Still Learning
Hi,

The following syntax works when used within a subroutine but not when
declaring an optional parameter in a sub definition:

Within sub:

Dim arr(,) as integer = {{0}, {0}}

Declaration:

Private Sub TempName(byval field1 as string, optional byval arr(,) as
integer =  {{0}, {0}} )

The Sub Declaration put a squiggly mark under the first { and states
"expression expected". I've tried different variations and searched books and
the web to no avail. Is this a bug or am I using incorrect syntax?

Thanks!
NJ

Author
13 Oct 2005 12:33 AM
David Anton
The default value for an optional parameter must be constant.  An array is
not considered a constant.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up outdated VB.NET code


Show quote
"Still Learning" wrote:

> Hi,
>
> The following syntax works when used within a subroutine but not when
> declaring an optional parameter in a sub definition:
>
> Within sub:
>
> Dim arr(,) as integer = {{0}, {0}}
>
> Declaration:
>
> Private Sub TempName(byval field1 as string, optional byval arr(,) as
> integer =  {{0}, {0}} )
>
> The Sub Declaration put a squiggly mark under the first { and states
> "expression expected". I've tried different variations and searched books and
> the web to no avail. Is this a bug or am I using incorrect syntax?
>
> Thanks!
> NJ

AddThis Social Bookmark Button