Solved

Optional Byte Array Parameter

Posted on 2002-07-10
5
436 Views
Last Modified: 2008-03-06
I canNOT get this right.  I just want my first parameter to be an optional byte array.  The most recent code I've tried is below, and the syntax error I get is "Constant expression is required".

How the heck do I supply a default value for this optional byte array, so that it's an empty byte array by default?  (Ubound(a) = 0, or better yet, Ubound(a) < 0)?

Thanks a bunch.

   Private Function StartXMLDecompressorThread( _
      Optional ByRef ByteArrayData() As Byte = New Byte() {}, _
      Optional ByVal sEXEPath As String = "", _
      Optional ByVal sXMLPath As String = "", _
      Optional ByVal sOutputPath As String = "" _
      ) _
      As Integer

0
Comment
Question by:bryker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Accepted Solution

by:
naveenkohli earned 100 total points
ID: 7143760
This is by rule that you can only supply contant values for optional arguments. You can't use "new" operator in the argument definition. You should be able to set this array argument to "null" by default. And then in function call you will check if this argument value is null or not.
0
 
LVL 10

Expert Comment

by:GoodJun
ID: 7143788
tried
Optional ByRef ByteArrayData() As Byte =nothing
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7143844
Did you ever consider altering this to be an overloaded function?  Or is it just too many optional arguments to consider (maybe rework it a bit)?
0
 

Author Comment

by:bryker
ID: 7143848
Man, do I feel like an idiot.  I keep forgetting that EVERYTHING in .NET is an object, and so can be legitimately set to Nothing.

Thanks for the help.
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 7143852
And have you tried:

Optional ByRef ByteArrayData() As Byte = Nothing
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Easy filter aspnet 2 46
Asp.Net Session Question 2 47
VB.net/VSTO Excel Add-in 2 37
Intermittent OleDbConnection Error 20 51
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question