我有一個二維數組,其大小在()內不是靜態的。即代碼將在稍後分配大小。我想傳入我的函數這個數組,所以我可以使用它來執行很多代碼。VB:將二維數組傳遞給Sub
我的數組:
'generate Ingredient array
Dim Ingredients(checkCount2 - 1, 3) As String
Dim maxDim0 As Integer = UBound(Ingredients, 1)
Dim maxDim1 As Integer = UBound(Ingredients, 2)
我曾嘗試以下:
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)
和等,但我不斷收到這樣的錯誤:
(Ingredients, ... : Value of type '2-dimensional array of String' cannot be converted to '1-dimension
和等
我的功能是:
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
如何通過任何建議我數組放入函數調用?
下面引用和其他許多人:
https://msdn.microsoft.com/en-us/library/5dk93f6e(v=vs.90).aspx
'GenerateNewImport(Ingredients,F_IDCode,F_Description,F_VersionDate,F_VersionNumber)'在我的測試用例中工作。 – Misery
對不起,這個方法'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)''''可以使用你的一個例子'GenerateNewImport成分,F_IDCode,F_Description,F_VersionDate,F_VersionNumber)'......實際問題是什麼? – djv
@Verdolino問題是我無法通過我的函數內我的數組。它給我提到的錯誤。 Romulus001回答了我的問題。問題是我的函數本身沒有正確檢查我的二維數組,雖然我正在使用'GenerateNewImport(Ingredients,..)'正確傳遞它' – narue1992