I created some code to grab serial port data and import it into excel. The data that comes in is in the following format;
D 4.7618 uS/cm 98.627 %Rej 346.73 uS/cm 70.573 DegF 0130
This string has a CR on the end. I am trying to split this into an array and then extract the data that I want into cells in excel. The code that I am using is this;
Private Sub XMCommCRC1_OnComm()
Static sInput As String
Dim sTerminator As String
Dim Buffer As Variant
Dim dLim() As String
' Branch according to the CommEvent property.
Select Case XMCommCRC1.CommEvent
Case XMCOMM_EV_RECEIVE
Buffer = XMCommCRC1.InputData
sInput = sInput & Buffer
' Puts the data from the com port into this variable
If Worksheets("Settings").Range("Terminator") = "CR/LF" Then
sTerminator = vbCrLf
' Determines the terminator from cell on settings sheet
Else
sTerminator = vbCr
End If
If Right$(sInput, Len(sTerminator)) = sTerminator Then
' Parses string for terminator and puts the string
' in the active cell and indexes one row
dLim = Split(sInput)
ActiveCell.Value = dLim(1)
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = dLim(3)
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = dLim(5)
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = dLim(7)
ActiveCell.Offset(1, -3).Select
Erase dLim
' Clears the data from the variable
sInput = ""
End If
End Select
End Sub
The problem is that only array elements 0-2 get populated, all the elements after 2 are empty. I'm not a VB programmer and am amazed that I got this far with my code, so please keep that in mind with any help that is offered.
D 4.7618 uS/cm 98.627 %Rej 346.73 uS/cm 70.573 DegF 0130
This string has a CR on the end. I am trying to split this into an array and then extract the data that I want into cells in excel. The code that I am using is this;
Private Sub XMCommCRC1_OnComm()
Static sInput As String
Dim sTerminator As String
Dim Buffer As Variant
Dim dLim() As String
' Branch according to the CommEvent property.
Select Case XMCommCRC1.CommEvent
Case XMCOMM_EV_RECEIVE
Buffer = XMCommCRC1.InputData
sInput = sInput & Buffer
' Puts the data from the com port into this variable
If Worksheets("Settings").Range("Terminator") = "CR/LF" Then
sTerminator = vbCrLf
' Determines the terminator from cell on settings sheet
Else
sTerminator = vbCr
End If
If Right$(sInput, Len(sTerminator)) = sTerminator Then
' Parses string for terminator and puts the string
' in the active cell and indexes one row
dLim = Split(sInput)
ActiveCell.Value = dLim(1)
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = dLim(3)
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = dLim(5)
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = dLim(7)
ActiveCell.Offset(1, -3).Select
Erase dLim
' Clears the data from the variable
sInput = ""
End If
End Select
End Sub
The problem is that only array elements 0-2 get populated, all the elements after 2 are empty. I'm not a VB programmer and am amazed that I got this far with my code, so please keep that in mind with any help that is offered.