Attribute VB_Name = "modMcaStatus" Option Explicit Public Function LoadSpectrumStatus(strFilename As String) As Variant Dim bufferSTATUS As Variant Dim iSizeStatus As ArrayIndex Dim idxStatus As Long Dim iPos As Integer Dim strMsg As String bufferSTATUS = GetSpectrumStatus(strFilename) iSizeStatus = GetArrayIndex(bufferSTATUS) If (TestDppStatus(bufferSTATUS)) Then 'do conversion 'remove all labels strMsg = "" For idxStatus = iSizeStatus.idxL To iSizeStatus.idxU iPos = InStr(1, bufferSTATUS(idxStatus), ": ") bufferSTATUS(idxStatus) = Mid(bufferSTATUS(idxStatus), iPos + 2) strMsg = strMsg & bufferSTATUS(idxStatus) & vbNewLine Next 'MsgBox strMsg LoadSpectrumStatus = bufferSTATUS End If End Function Public Function GetSpectrumStatus(strFilename As String) As Variant Dim strMCAData As Variant 'entire file contents in array of strings Dim iSize As ArrayIndex ' Dim MCAStatus() As String Dim i As Long Dim j As Long Dim lastStat As Long Dim iStatus As ArrayIndex strMCAData = GetMcaFile(strFilename) 'read mca file data iSize = GetArrayIndex(strMCAData) 'get size of mca file iStatus = GetStatusIndex(strMCAData) 'get location of spectrum data lastStat = iStatus.idxU - iStatus.idxL ReDim MCAStatus(lastStat) j = 0 For i = iStatus.idxL To iStatus.idxU 'load the data into an array for processing MCAStatus(j) = strMCAData(i) j = j + 1 Next GetSpectrumStatus = MCAStatus End Function '''''<> '''''Device Type: PX4 '''''Serial Number: 1070 '''''Firmware: 4.01 '''''FPGA: 4.00 '''''Fast Count: 215664 '''''Slow Count: 81497 '''''Accumulation Time: 7901 '''''Dead Time: 62.21% '''''HV Volt: 94V '''''TEC Temp: 243K '''''Board Temp: 31°C '''''<> Public Function GetStatusIndex(strMCAData As Variant) As ArrayIndex Dim FileNum As Integer Dim iSize As ArrayIndex Dim iData As ArrayIndex Dim i As Long On Error GoTo GetStatusIndexErr GetStatusIndex.idxL = -1 'indicates not found GetStatusIndex.idxU = -1 'indicates not found iSize = GetArrayIndex(strMCAData) 'get the indices of the array for For i = iSize.idxL To iSize.idxU If (StrComp(strMCAData(i), "<>", vbTextCompare) = 0) Then GetStatusIndex.idxL = i + 1 If (StrComp(strMCAData(i), "<>", vbTextCompare) = 0) Then GetStatusIndex.idxU = i - 1 'roi is always ends at data Next Exit Function GetStatusIndexErr: GetStatusIndex.idxL = -1 'indicates not found GetStatusIndex.idxU = -1 'indicates not found MsgBox "GetStatusIndex " & Err.Description, vbCritical End Function Public Function TestDppStatus(strStatusArr As Variant) As Boolean Dim iStatus As Integer Dim strStatusLabel As String Dim iSize As ArrayIndex Dim strTestVal As String TestDppStatus = True iSize = GetArrayIndex(strStatusArr) If ((iSize.idxL <> 0) Or (iSize.idxU <> 10)) Then TestDppStatus = False Exit Function End If For iStatus = iSize.idxL To iSize.idxU strStatusLabel = GetStatusLabel(iStatus) strTestVal = strStatusArr(iStatus) If (InStr(1, strTestVal, strStatusLabel, vbTextCompare) = 0) Then TestDppStatus = False MsgBox "Fail " & iStatus End If Next End Function Public Function GetStatusLabel(iStatus As Integer) As String Dim strStatusLabel As String Select Case iStatus Case 0 strStatusLabel = "Device Type: " Case 1 strStatusLabel = "Serial Number: " Case 2 strStatusLabel = "Firmware: " Case 3 strStatusLabel = "FPGA: " Case 4 strStatusLabel = "Fast Count: " Case 5 strStatusLabel = "Slow Count: " Case 6 strStatusLabel = "Accumulation Time: " Case 7 strStatusLabel = "Dead Time: " Case 8 strStatusLabel = "HV Volt: " Case 9 strStatusLabel = "TEC Temp: " Case 10 strStatusLabel = "Board Temp: " End Select GetStatusLabel = strStatusLabel End Function Public Function GetStatusLabelIndex(strStatus As String) As Integer Select Case strStatus Case "Device Type:" GetStatusLabelIndex = 0 Case "Serial Number:" GetStatusLabelIndex = 1 Case "Firmware:" GetStatusLabelIndex = 2 Case "FPGA:" GetStatusLabelIndex = 3 Case "Fast Count:" GetStatusLabelIndex = 4 Case "Slow Count:" GetStatusLabelIndex = 5 Case "Accumulation Time:" GetStatusLabelIndex = 6 Case "Dead Time:" GetStatusLabelIndex = 7 Case "HV Volt:" GetStatusLabelIndex = 8 Case "TEC Temp:" GetStatusLabelIndex = 9 Case "Board Temp:" GetStatusLabelIndex = 10 Case Else GetStatusLabelIndex = -1 End Select End Function