M
mattc66 via AccessMonster.com
Having the a problem with the below function. I am parsing data below:
CC,4.5x5x7,C2
CC,4x5x7,C2
PB,5.5x5.5x8,C2,ModelName
'to
fld1 fld2 fld3 fld4 fld5 fld6
CC 4.5 5 7 C2
CC 4 5 7 C2
PB 5.5 5.5 8 C2 ModelName
The problem is it works great if all 6 flds are populated. However if the
last fld is null I get an error message "Subscript out of range".
Below is the code. What can I do to resolve this issue?
Public Function ParseData(pstrText As String, _
pintColumn As Integer) As String
On Error GoTo Err_ParseData
Dim arCSV
Dim arX
'create 3 comma separated values
arCSV = Split(pstrText, ",")
'split the "x" separated values
arX = Split(arCSV(1), "x")
Select Case pintColumn
Case 1
ParseData = arCSV(0)
Case 2
ParseData = arX(0)
Case 3
ParseData = arX(1)
Case 4
ParseData = arX(2)
Case 5
ParseData = arCSV(2)
Case 6
ParseData = arCSV(3)
End Select
Exit_ParseData:
Exit Function
Err_ParseData:
MsgBox Err.DESCRIPTION
Resume Exit_ParseData
End Function
CC,4.5x5x7,C2
CC,4x5x7,C2
PB,5.5x5.5x8,C2,ModelName
'to
fld1 fld2 fld3 fld4 fld5 fld6
CC 4.5 5 7 C2
CC 4 5 7 C2
PB 5.5 5.5 8 C2 ModelName
The problem is it works great if all 6 flds are populated. However if the
last fld is null I get an error message "Subscript out of range".
Below is the code. What can I do to resolve this issue?
Public Function ParseData(pstrText As String, _
pintColumn As Integer) As String
On Error GoTo Err_ParseData
Dim arCSV
Dim arX
'create 3 comma separated values
arCSV = Split(pstrText, ",")
'split the "x" separated values
arX = Split(arCSV(1), "x")
Select Case pintColumn
Case 1
ParseData = arCSV(0)
Case 2
ParseData = arX(0)
Case 3
ParseData = arX(1)
Case 4
ParseData = arX(2)
Case 5
ParseData = arCSV(2)
Case 6
ParseData = arCSV(3)
End Select
Exit_ParseData:
Exit Function
Err_ParseData:
MsgBox Err.DESCRIPTION
Resume Exit_ParseData
End Function