名前とその値を 2D 配列に挿入しようとしています:
____________
| name| value| index 0
|name1|value1| index 1
|name2|value2| index 2 ...
.
.
.
私がこれまでに行ったこと:
Function ParseCSV(ByVal FileName As String)
Dim FS 'As Scripting.FileSystemObject
Dim Txt 'As Scripting.TextStream
Dim CSVLine
Dim arrayOfElements
Dim nbErrors As Integer
Dim namesNotInDb() As String
Dim element As Variant
Dim errorMsg As String
Dim namesAgeMatrix() As String
Dim nbrAges As Integer
Set FS = CreateObject("Scripting.FileSystemObject")
Set Txt = FS.OpenTextFile(FileName, 1, False)
nbrAges = 0
Do While Not Txt.AtEndOfStream
If nbrAges = 0 Then ReDim namesAgeMatrix(0, 1) Else ReDim Preserve namesAgeMatrix(nbrAges, 1)
CSVLine = Txt.ReadLine
arrayOfElements = Split(CSVLine, ",")
namesAgeMatrix(nbrAges, 0) = arrayOfElements(0)
If arrayOfElements(1) = "N/A" Then
nbErrors = nbErrors + 1
ReDim Preserve snamesNotInDb(nbErrors)
namesNotInDb(nbErrors) = arrayOfElements(0)
instrumentPriceMatrix(nbrInstruments, 1) = 0
Else
namesAgeMatrix(nbrAges, 1) = arrayOfElements(1)
End If
nbrAges = nbrAges + 1
Loop
Txt.Close
If nbErrors > 0 Then 'displaying error/success message
errorMsg = ""
For Each name In namesNotInDb
errorMsg = errorMsg & name & " "
Next
MsgBox "Warning : " & errorMsg & "have no feed in DB. Name set by default to John.", vbExclamation
Else
MsgBox "Importation success!", vbOKOnly
End If
ParseCSV = namesAgeMatrix
End Function
私が得るエラーSubscription our of range
は次のとおりです:
Else ReDim namesAgeMatrix(nbrAges, 1)
アレイを適切な方法で Redim にするにはどうすればよいですか?
前もって感謝します。