Solved

Optional Byte Array Parameter

Posted on 2002-07-10
5
423 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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