Attribute VB_Name = "modMcaCfg" Option Explicit 'combined xls and mca filter for dialog Public Const dlgMCA_XLS_Filter As String = "Amptek Spectrum (*.mca)|*.mca|Excel Files (*.xls)|*.xls|All Files (*.*)|*.*" Public Function LoadSpectrumCFG(strFilename As String, strFileNew As String, strDesc As String) As Variant Dim bufferCFG As Variant Dim iSizeCFG As ArrayIndex ' Dim i As Long Dim iPos As Integer Dim bufferCFGNew(30) As String Dim strMsg As String bufferCFG = GetSpectrumCFG(strFilename) iSizeCFG = GetArrayIndex(bufferCFG) If (TestDppConfig(bufferCFG)) Then 'do conversion 'remove all labels For i = iSizeCFG.idxL To iSizeCFG.idxU iPos = InStr(1, bufferCFG(i), ": ") bufferCFG(i) = Mid(bufferCFG(i), iPos + 2) Next 'update BLR If (InStr(1, bufferCFG(9), "off", vbTextCompare)) Then bufferCFG(9) = "Off" Else iPos = InStr(1, bufferCFG(9), "DN:") bufferCFG(9) = Mid(bufferCFG(9), iPos + 3) iPos = InStr(1, bufferCFG(9), "UP:") bufferCFG(9) = Left(bufferCFG(9), iPos - 1) & Mid(bufferCFG(9), iPos + 3) End If 'remove PUR prefix from PUR_Enable value 4 iPos = InStr(1, bufferCFG(4), "PUR") bufferCFG(4) = Mid(bufferCFG(4), iPos + 3) 'remove RTD prefix from RTD_ON_OFF value 5 iPos = InStr(1, bufferCFG(5), "RTD") bufferCFG(5) = Mid(bufferCFG(5), iPos + 3) 'remove " FS" from SlowChThreshold value 13 iPos = InStr(1, bufferCFG(13), " FS") bufferCFG(13) = Left(bufferCFG(13), iPos - 1) If (DppDevice = DPPDP5) Then 'remove " FS" from RTD Slow Threshold value 7 iPos = InStr(1, bufferCFG(7), " FS") bufferCFG(7) = Left(bufferCFG(7), iPos - 1) Else 'remove " FS" from RTD Threshold value 6 iPos = InStr(1, bufferCFG(6), " FS") bufferCFG(6) = Left(bufferCFG(6), iPos - 1) End If 'add filename entry bufferCFGNew(0) = strFileNew 'add description entry bufferCFGNew(1) = strDesc For i = 0 To 9 bufferCFGNew(i + 2) = bufferCFG(i) Next 'remove mca mode line (don't save to new struct) 'remove mcs setting (don't save to new struct) For i = 12 To 30 bufferCFGNew(i) = bufferCFG(i) Next strMsg = "" For i = 0 To 30 strMsg = strMsg & bufferCFGNew(i) & vbNewLine Next ' Clipboard.Clear ' Clipboard.SetText strMsg LoadSpectrumCFG = bufferCFGNew End If End Function Public Function GetSpectrumData(strFilename As String) As Variant Dim strMCAData As Variant 'entire file contents in array of strings Dim iSize As ArrayIndex ' Dim MCAData() As Double Dim i As Long Dim j As Long Dim lastCh As Long Dim iData As ArrayIndex strMCAData = GetMcaFile(strFilename) 'read mca file data iSize = GetArrayIndex(strMCAData) 'get size of mca file iData = GetDataIndex(strMCAData) 'get location of spectrum data lastCh = iData.idxU - iData.idxL ReDim MCAData(lastCh) j = 0 For i = iData.idxL To iData.idxU 'load the data into an array for processing MCAData(j) = CDbl(strMCAData(i)) j = j + 1 Next GetSpectrumData = MCAData End Function Public Function GetSpectrumROI(strFilename As String) As Variant Dim strMCAData As Variant 'entire file contents in array of strings Dim iSize As ArrayIndex ' Dim MCAData() As String Dim i As Long Dim j As Long Dim lastCh As Long Dim iROI As ArrayIndex strMCAData = GetMcaFile(strFilename) 'read mca file data iSize = GetArrayIndex(strMCAData) 'get size of mca file iROI = GetROIIndex(strMCAData) 'get location of spectrum data lastCh = iROI.idxU - iROI.idxL ReDim MCAData(lastCh) j = 0 For i = iROI.idxL To iROI.idxU 'load the data into an array for processing MCAData(j) = strMCAData(i) j = j + 1 Next GetSpectrumROI = MCAData End Function Public Function GetSpectrumCFG(strFilename As String) As Variant Dim strMCAData As Variant 'entire file contents in array of strings Dim iSize As ArrayIndex ' Dim MCAData() As String Dim i As Long Dim j As Long Dim lastCh As Long Dim iCfg As ArrayIndex strMCAData = GetMcaFile(strFilename) 'read mca file data iSize = GetArrayIndex(strMCAData) 'get size of mca file iCfg = GetCFGIndex(strMCAData) 'get location of spectrum data lastCh = iCfg.idxU - iCfg.idxL ReDim MCAData(lastCh + 1) j = 0 For i = iCfg.idxL To iCfg.idxU 'load the data into an array for processing MCAData(j) = strMCAData(i) j = j + 1 Next MCAData(j) = strMCAData(iCfg.idxU + 3) 'get the device type from status GetSpectrumCFG = MCAData End Function Public Function GetCFGIndex(strMCAData As Variant) As ArrayIndex Dim FileNum As Integer Dim iSize As ArrayIndex Dim iData As ArrayIndex Dim i As Long On Error GoTo GetCFGIndexErr GetCFGIndex.idxL = -1 'indicates not found GetCFGIndex.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 GetCFGIndex.idxL = i + 1 If (StrComp(strMCAData(i), "<>", vbTextCompare) = 0) Then GetCFGIndex.idxU = i - 1 'roi is always ends at data Next Exit Function GetCFGIndexErr: GetCFGIndex.idxL = -1 'indicates not found GetCFGIndex.idxU = -1 'indicates not found MsgBox "GetCFGIndex " & Err.Description, vbCritical End Function 'configuration class (clsDPPConfig) settings Public Function TestDppConfig(strCfgArr As Variant) As Boolean Dim iCfg As Integer Dim strCfgLabel As String Dim iSize As ArrayIndex Dim strTestVal As String TestDppConfig = True iSize = GetArrayIndex(strCfgArr) If ((iSize.idxL <> 0) Or (iSize.idxU <> 30)) Then TestDppConfig = False Exit Function End If For iCfg = iSize.idxL To iSize.idxU strCfgLabel = GetCfgLabel(iCfg) strTestVal = strCfgArr(iCfg) If (InStr(1, strTestVal, strCfgLabel, vbTextCompare) = 0) Then TestDppConfig = False MsgBox "Fail " & iCfg End If Next End Function 'configuration class (clsDPPConfig) settings Public Function GetCfgLabel(iCfg As Integer) As String Dim strCfgLabel As String Select Case iCfg Case 0 strCfgLabel = "COM Port: " Case 1 strCfgLabel = "Rise: " Case 2 strCfgLabel = "Top: " Case 3 strCfgLabel = "Fast Threshold: " Case 4 strCfgLabel = "PUR Enable: " Case 5 strCfgLabel = "RTD ON/OFF: " Case 6 If (DppDevice = DPPDP5) Then strCfgLabel = "RTD Ratio: " Else strCfgLabel = "RTD Threshold: " End If Case 7 If (DppDevice = DPPDP5) Then strCfgLabel = "RTD Slow Thresh: " Else strCfgLabel = "RTD Fast HWHM: " End If Case 8 strCfgLabel = "AutoBaseline: " Case 9 strCfgLabel = "BLR: " Case 10 strCfgLabel = "Acquisition Mode: " Case 11 strCfgLabel = "MCS Timebase: " Case 12 strCfgLabel = "MCA Channels: " Case 13 strCfgLabel = "Slow Threshold: " Case 14 strCfgLabel = "Buffer Select: " Case 15 strCfgLabel = "Gate Input (TTL): " Case 16 strCfgLabel = "Preset: " Case 17 strCfgLabel = "Coarse Gain: " Case 18 strCfgLabel = "Fine Gain: " Case 19 strCfgLabel = "Input Polarity: " Case 20 strCfgLabel = "Input Offset: " Case 21 strCfgLabel = "Pole Zero: " Case 22 strCfgLabel = "Det Rst Lockout: " Case 23 strCfgLabel = "TEC: " Case 24 strCfgLabel = "HV: " Case 25 strCfgLabel = "Preamp Power: " Case 26 strCfgLabel = "Analog Out: " Case 27 strCfgLabel = "Offset: " Case 28 strCfgLabel = "Aux: " Case 29 strCfgLabel = "Audio: " Case 30 strCfgLabel = "Device Type: " End Select GetCfgLabel = strCfgLabel End Function Public Function GetFileExtension(ByVal strFilename As String) As String Dim lPos As Long Dim lLastPos As Long On Error GoTo GetFileExtensionErr GetFileExtension = "" lLastPos = InStr(strFilename, ".") Do While lLastPos lPos = lLastPos lLastPos = InStr(lPos + 1, strFilename, ".") Loop If lPos > 0 Then GetFileExtension = Mid$(strFilename, lPos + 1) End If Exit Function GetFileExtensionErr: 'program runs in silent mode for unattended operation 'ErrorLog "GetFileExtension: " & Err.Description End Function