Is it possible?

To OPTIONAL pass an array into a Function?

Page 1 of 1

2 Replies - 596 Views - Last Post: 19 June 2008 - 06:27 AM Rate Topic: -----

#1 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Is it possible?

Post icon  Posted 19 June 2008 - 03:53 AM

If it is possible?
How do I specify the default to be a Empty Array?

Tried using code below.
Private Function Foo(byref Option A() as Type = {} )
End Function 



Solved the problem differently by changing the Optional variable A to a String.
But suppose I want to use a type that isn't easily converted to a string.
Is This A Good Question/Topic? 0
  • +

Replies To: Is it possible?

#2 RodgerB  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 66
  • View blog
  • Posts: 2,284
  • Joined: 21-September 07

Re: Is it possible?

Posted 19 June 2008 - 05:06 AM

Set the object to equal Nothing (null), and initialize the optional value when function is called.

Private Function lal(Optional ByVal opt() As String = Nothing) As Boolean
    opt= New String(0) {"weeeeeee"}
    Return True
End Function


Hope that helps. :)
Was This Post Helpful? 0
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Is it possible?

Posted 19 June 2008 - 06:27 AM

RodgerB thank-you I'd forgotten about Nothing.
Used the code below as I needed empty array.
Private Function lal(Optional ByVal opt() As String = Nothing) As Boolean
 If opt is nothing then 
  opt= New String() {} ' Empty Set required.
 end if
 Return True
End Function

[/quote]
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1