Passing Optional Arguments into an Array Function

  • Thread starter Thread starter Winshent
  • Start date Start date
W

Winshent

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?
 
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
 
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
 
Jay, i have used your method and it seems to have worked nicely..

Thanks to you both for responding.
 

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