narue1992 narue1992 - 23 days ago 11
Vb.net Question

VB: Pass 2D array into Sub

I have a 2D array whose size inside the () is not static. Aka the code will assign the size later. I want to pass into my function this array so I can perform a lot of code using it.

My array:

'generate Ingredient array
Dim Ingredients(checkCount2 - 1, 3) As String
Dim maxDim0 As Integer = UBound(Ingredients, 1)
Dim maxDim1 As Integer = UBound(Ingredients, 2)


I have tried the following:

For i As Integer = 0 To maxDim0
For j As Integer = 0 To maxDim1
GenerateNewImport(Ingredients(i, j), F_IDCode, F_Description, F_VersionDate, F_VersionNumber)
Next j
Next i


OR

GenerateNewImport(Ingredients, F_IDCode, F_Description, F_VersionDate, F_VersionNumber)


OR

GenerateNewImport(Ingredients(), F_IDCode, F_Description, F_VersionDate, F_VersionNumber)


OR

GenerateNewImport(Ingredients(checkCount2-1, 3), F_IDCode, F_Description, F_VersionDate, F_VersionNumber)


and etc but I keep getting errors like:

(Ingredients, ... : Value of type '2-dimensional array of String' cannot be converted to '1-dimension


and etc

My function is:

Sub GenerateNewImport(ByVal Ingredients(,) As String, ByVal F_IDCode As String, ByVal F_Description As String, ByVal F_VersionDate As String, ByVal F_VersionNumber As String)

End Sub


Any suggestions on how to pass my array into the function call?

Referenced below and many others:

https://msdn.microsoft.com/en-us/library/5dk93f6e(v=vs.90).aspx

Answer
ByVal Ingredients(,) As String

has to replaced by

ByVal Ingredients As String(,)