Newby question: How do you handles arrays with functions?

  • Thread starter Thread starter Blue Streak
  • Start date Start date
B

Blue Streak

Just some basic questions because none of my reference manuals cover
this explicitly:

1) If you want have an argument as an array of integers would this
be the correct declaration?

Function foo(bar() as Integer) as Integer
...
End Function

2) If you wanted to *return* an array of integers from the function
would this declaration be correct?

Function foo(bar as Integer) as Integer()
...
End Function

TIA...
 
Since you went to the trouble of writing it out here, you could have simply
tried it out. Your code looks fine, except I think () should come after
integer not bar in the 1st example

For the parameters, you could declare it as ParamArray which would let you
pass in 1 value, great replacement for overloading (in some cases)

Function foo (ParamArray bar as integer()

end function

you can now call foo with either a single value, or an array, or a comma
separated list

foo(1)
foo(arr)
foo(1,2,3,4,5)

ParramArray _must_ be the last parameter of a function.

Karl
 
Karl,

In VB.NET the parentheses may be placed just after the parameter name or
after the type declaration. It's up to the developer, but both ways work.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top