473,385 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Passing Optional Arguments into an Array Function

I want to pass optional arguments to build up varios strings, is this
possible?

look at arrTBL(1,3) in the code below:

===========================================

Public Function arrTBL(Optional ByVal DataSetName As String = "") As
String(,)
Dim DSN As String = DataSetName

arrTBL(1, 1) = "UP_" & Session("mCallCentreID") & "_Results_Daily"
arrTBL(1, 2) = "DailyCallSt"
arrTBL(1, 3) = "INSERT INTO " & arrTBL(1, 1) & "SELECT " & DSN &
".field1 FROM " & DSN & ";"

End function

==============================================

I would like to be able to do this, but the other arrays dont like it,
too many arguments etc..

Is there a way round this?
Nov 21 '05 #1
3 4761
Winshent,
VB.NET is trying to recursively call your routine, rather then treat arrTBL
as a variable.

To avoid the ambiguity this is causing I would define a variable for the
return value, use this value, then return it.

Something like:
Public Function arrTBL(Optional ByVal DataSetName As String = "") As
String(,)
Dim value(1,3) As String
Dim DSN As String = DataSetName
value(1, 1) = "UP_" & Session("mCallCentreID") & "_Results_Daily"
value(1, 2) = "DailyCallSt"
value(1, 3) = "INSERT INTO " & value(1, 1) & "SELECT " & DSN & ".field1 FROM " & DSN & ";"
Return value
End function
NOTE: The optional parameter has nothing to do with it, try the following:

Public Function arrTBL(ByVal x As Integer, ByVal y As Integer) As
String(,)

arrTBL(1,1) = "Hello!"

End Function

"arrTBL(1,1)" is treated as a recursive call so you get an error about
"Expression is a value and therefore cannot be the target of an assignment".

Hope this helps
Jay
"Winshent" <wi*************@yahoo.co.uk> wrote in message
news:f5**************************@posting.google.c om...I want to pass optional arguments to build up varios strings, is this
possible?

look at arrTBL(1,3) in the code below:

===========================================

Public Function arrTBL(Optional ByVal DataSetName As String = "") As
String(,)
Dim DSN As String = DataSetName

arrTBL(1, 1) = "UP_" & Session("mCallCentreID") & "_Results_Daily"
arrTBL(1, 2) = "DailyCallSt"
arrTBL(1, 3) = "INSERT INTO " & arrTBL(1, 1) & "SELECT " & DSN &
".field1 FROM " & DSN & ";"

End function

==============================================

I would like to be able to do this, but the other arrays dont like it,
too many arguments etc..

Is there a way round this?

Nov 21 '05 #2
Whinshent,

I can do it in this way, the other way I did not try.
\\\
Dim DSN As String = "whatever"
Dim arrTbl As New ArrayList
arrTbl.Add(New ArrayList)
DirectCast(arrTbl(0), ArrayList).Add("UP_" & "mCallCentreID" _
& "_Results_Daily")
DirectCast(arrTbl(0), ArrayList).Add("DailyCallSt")
DirectCast(arrTbl(0), ArrayList).Add("INSERT INTO " & _
DirectCast(arrTbl(0), ArrayList)(0).ToString & _
"SELECT " & DSN & ".field1 FROM " & DSN & ";")
MessageBox.Show(DirectCast(arrTbl(0), ArrayList)(2).ToString)
///

I hope this helps?

Cor

"Winshent" <wi*************@yahoo.co.uk>
I want to pass optional arguments to build up varios strings, is this
possible?

look at arrTBL(1,3) in the code below:

===========================================

Public Function arrTBL(Optional ByVal DataSetName As String = "") As
String(,)
Dim DSN As String = DataSetName

arrTBL(1, 1) = "UP_" & Session("mCallCentreID") & "_Results_Daily"
arrTBL(1, 2) = "DailyCallSt"
arrTBL(1, 3) = "INSERT INTO " & arrTBL(1, 1) & "SELECT " & DSN &
".field1 FROM " & DSN & ";"

End function

==============================================

I would like to be able to do this, but the other arrays dont like it,
too many arguments etc..

Is there a way round this?

Nov 21 '05 #3
Jay, i have used your method and it seems to have worked nicely..

Thanks to you both for responding.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
2
by: windandwaves | last post by:
Hi Folk I have the following function var a = new Array(4); a = new Array(45); //status (on or off) a = new Array(45); //name of the region a = new Array(45); //on mouse over a = new...
39
by: Mike MacSween | last post by:
Just spent a happy 10 mins trying to understand a function I wrote sometime ago. Then remembered that arguments are passed by reference, by default. Does the fact that this slowed me down...
17
by: Charles Sullivan | last post by:
The library function 'qsort' is declared thus: void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); If in my code I write: int cmp_fcn(...); int...
2
by: Tobias Olbort | last post by:
Hello, i've a outer function, which takes a params-array as a parameter. I want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to...
16
by: ad | last post by:
Does C#2.0 support optional parameters like VB.NET: Function MyFunction(Optional ByVal isCenter As Boolean = False)
7
by: Bonzo | last post by:
>From within a function, I want to pass a/some parameters to another function, AND all arguments, passed into this function. e.g. function firstFunction(){ //this function may have been...
2
by: Mary Pegg | last post by:
No point re-inventing the wheel, so thought I'd see if anybody's got some good example code kicking around. (Please excuse trivial syntactical errors, it's all coming off the top of my head). ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.