Attribute VB_Name = "modDisplayCfg"
Option Explicit

'@bfunc Saves the configuration class (clsDPPConfig) settings
'to a display string, includes description labels.
'@bparm configuration class to be displayed
'@rdesc configuration display string with description labels
'@devnote uses all DPP dialog control classes to convert values
Public Function ShowConfigSettingStrings() As String
    Dim strConfig As String
    Dim strTemp As String
    
    strConfig = ""
    'saves the comm port string COM
    'if port > 0 then is a ser com port, if = 0 then is USB, else not set
    strConfig = strConfig & "COM Port: " & GetPortStrFromVal(Port) & vbNewLine

    strTemp = GetRiseStringFromVal(Rise, Avg)
    strConfig = strConfig & "Rise: " & strTemp & vbNewLine
    strTemp = GetTopStringFromVal(FlatTop, Avg)
    strConfig = strConfig & "Top: " & strTemp & vbNewLine
    
    strConfig = strConfig & "Fast Threshold: " & FastChThreshold & vbNewLine
    strConfig = strConfig & "PUR Enable: " & GetPUROnOffTextFromVal(PUREnable) & vbNewLine
    
    'saves RTD OFF/ON State,slow/fast values
    strTemp = GetRTDOnTextFromVal(CBool(RTDOn))
    strConfig = strConfig & "RTD ON/OFF: " & strTemp & vbNewLine
    
    strTemp = GetRTDSlowStrFromVal(RTDSlow)
    strConfig = strConfig & "RTD Threshold: " & strTemp & vbNewLine
    
    strTemp = GetRTDFastStrFromVal(RTDFast)
    strConfig = strConfig & "RTD Fast HWHM: " & strTemp & vbNewLine
    
     ' the following were added in v3.4
    strTemp = GetBaselineOnStrFromValShort(BaselineOn)
    strConfig = strConfig & "AutoBaseline: " & strTemp & vbNewLine
    
    strConfig = strConfig & "BLR: " & GetBLRStrFromVal(BLR) & vbNewLine
    strConfig = strConfig & "Acquisition Mode: " & GetAcqModeTextFromVal(AcqMode) & vbNewLine
    strConfig = strConfig & "MCS Timebase: " & GetTimebaseStrFromIndex(MCSTimebase) & vbNewLine
    
    'saves the setup string MCA+NumberOfChannels or MCADisable if disabled
    strTemp = GetMCAChannelsStrFromVal(MCAEnable, MCA)
    strConfig = strConfig & "MCA Channels: " & strTemp & vbNewLine
    strTemp = GetSlowChThresStrFromVal(SlowChThreshold)
    strConfig = strConfig & "Slow Threshold: " & strTemp & vbNewLine
    
    strTemp = GetBufferSelectDispStr(BufferSelect)
    strConfig = strConfig & "Buffer Select: " & strTemp & vbNewLine
    
    strTemp = GetGateValueString(Gate)
    strConfig = strConfig & "Gate Input (TTL): " & strTemp & vbNewLine   'print gate value
    strTemp = GetPresetTimeStrFromVal(Preset)
    strConfig = strConfig & "Preset: " & strTemp & vbNewLine
      
    strTemp = GetCoarseGainString(CoarseGain, DppDevice)
    strConfig = strConfig & "Coarse Gain: " & strTemp & vbNewLine     'save gain value in text form
    strTemp = GetFineGainString(FineGain)
    strConfig = strConfig & "Fine Gain: " & strTemp & vbNewLine      'save gain value in text form
    strTemp = GetInputPolarityString(InvertCG)
    strConfig = strConfig & "Input Polarity: " & strTemp & vbNewLine      'save gain value in text form
    strTemp = GetInputOffsetString(InputOffset)
    strConfig = strConfig & "Input Offset: " & strTemp & vbNewLine
    strTemp = GetPoleZeroString(PoleZero)
    strConfig = strConfig & "Pole Zero: " & strTemp & vbNewLine
    strTemp = GetDetResetTextFromVal(CInt(DetReset))
    strConfig = strConfig & "Det Rst Lockout: " & strTemp & vbNewLine
    strTemp = GetTECString(TEC)
    strConfig = strConfig & "TEC: " & strTemp & vbNewLine
    strTemp = GetHVString(HV)
    strConfig = strConfig & "HV: " & strTemp & vbNewLine
    strTemp = GetPreampPowerString(Pwr8_5SEL_On)
    strConfig = strConfig & "Preamp Power: " & strTemp & vbNewLine
    'save dac settings (change values 0-4 + DAC_Enable to DAC1-DAC5)
    'read dac val opt index and add 1 to get DAC opt value or DAC5 for off
    Dim DAC_Enable As Byte
    DAC_Enable = CByte(Abs(CBool(DAC > 0)))
    strConfig = strConfig & "Analog Out: " & GetDACHeaderStrFromVal(DAC_Enable, DAC) & vbNewLine
    strTemp = GetOutputOffsetStrFromVal(OutputOffset)
    strConfig = strConfig & "Offset: " & strTemp & vbNewLine
    strTemp = GetAuxComboStrFromIndex(AuxOut)
    strConfig = strConfig & "Aux: " & strTemp & vbNewLine
    strTemp = GetOutputOffsetStrFromVal(OutputOffset)
    strConfig = strConfig & "Offset: " & strTemp & vbNewLine
    strTemp = GetAudioString(AudibleCounter)
    strConfig = strConfig & "Audio: " & strTemp & vbNewLine
    ShowConfigSettingStrings = strConfig
End Function

Public Function GetTECString(TEC As Integer) As String
    Dim dblTemp As Double
    dblTemp = CDbl(TEC) * 3# / 4096# * 100#
    GetTECString = FormatNumber(dblTemp, 1) & "K"
End Function

Public Function GetHVString(HV As Integer) As String
    Dim dblTemp As Double
    dblTemp = CDbl(HV) * 3# / 4096# * 500#
    GetHVString = FormatNumber(dblTemp, 1) & "V"
End Function

Public Function GetPreampPowerString(Pwr8_5SEL_On As Boolean) As String
    If (Pwr8_5SEL_On) Then
        GetPreampPowerString = "8.5V"
    Else
        GetPreampPowerString = "5.0V"
    End If
End Function


'@mfunc <c CDppPX4Aux> get the Aux output option display string based on given Aux optionbox index
'@parm Aux optionbox index
'@rdesc Aux output option string display text (shape name or off)
'@devnote This is used in clsDPPFile.CreateSaveFileHeader.
Public Function GetAuxComboStrFromIndex(AuxOut As Long) As String
    Select Case AuxOut
        Case 0
            GetAuxComboStrFromIndex = "ICR"
        Case 1
            GetAuxComboStrFromIndex = "PILEUP"
        Case 2
            GetAuxComboStrFromIndex = "HOLD"
        Case 3
            GetAuxComboStrFromIndex = "ONESHOT"
        Case 4
            GetAuxComboStrFromIndex = "DET_RES"
        Case 5
            GetAuxComboStrFromIndex = "MCA_EN"
        Case 6
            GetAuxComboStrFromIndex = "TRIGGER"
        Case 7
            GetAuxComboStrFromIndex = "SCA8"
    End Select
End Function

Public Function GetAudioString(AudibleCounter As Byte)
    Select Case AudibleCounter
        Case 0
            GetAudioString = "Off"
        Case 1
            GetAudioString = "Low"
        Case 2
            GetAudioString = "Medium"
        Case 3
            GetAudioString = "High"
        Case Else
            GetAudioString = "Off"
    End Select
End Function

Public Function GetPoleZeroString(PoleZero As Integer) As String
    If (CBool(PoleZero)) Then
        GetPoleZeroString = CStr(PoleZero)
    Else
        GetPoleZeroString = "Off"
    End If
End Function

Public Function GetInputOffsetString(InputOffset As Long) As String
    Dim dblInputOffset As Double
    dblInputOffset = ((CDbl(InputOffset) - 2048#) / 1000#)
    GetInputOffsetString = FormatNumber(dblInputOffset, 3) & "V"
End Function

'get rise str from value
'@bfunc Get Rise value string from a Rise and Avg values.
'@bparm Rise value
'@bparm Avg value
'@rdesc Rise value string
Public Function GetRiseStringFromVal(RiseVal As Integer, AvgVal As Integer) As String
    If (AvgVal = 0) Then
        GetRiseStringFromVal = "12.8uS"     '"Rise Value Not Set"
    ElseIf (RiseVal = -1) Then
        GetRiseStringFromVal = "12.8uS"     '"Rise Value Not Set"
    Else
        GetRiseStringFromVal = FormatNumber((RiseVal * 0.8 * (2 ^ (AvgVal - 1))), 1) & "uS"
    End If
End Function

'get top str from value
'calculates the top width string from given FlatTop and Avg values
'@bfunc Get FlatTop value string from a FlatTop and Avg values.
'@bparm FlatTop value
'@bparm Avg value
'@rdesc FlatTop value string
Public Function GetTopStringFromVal(FlatTopVal As Integer, AvgVal As Integer) As String
    Dim dblTop As Double
    dblTop = 0.1 * (2 ^ AvgVal) * (FlatTopVal + 1)
    GetTopStringFromVal = FormatNumber(dblTop, 1) & "uS"
End Function

'@bfunc Get Slow Threshold display text string from Slow Threshold value.
'@bparm Slow Threshold value
'@rdesc Slow Threshold display text string
Public Function GetSlowChThresStrFromVal(byteSlowThres As Byte) As String
    GetSlowChThresStrFromVal = CStr(Int(byteSlowThres * 100# * 4# / 4096 * 100) / 100) + "% FS"
End Function

'@bfunc get the output DAC offset display string based on given offset value
'@rdesc output DAC offset display string
'@devnote This is used in clsDPPFile.
Public Function GetOutputOffsetStrFromVal(OffsetVal As Long) As String
    GetOutputOffsetStrFromVal = CStr(Int(((OffsetVal * 2 + ((OffsetVal * 2) > 127) * 256) * 1000 * 16 / 4096))) + "mV"
End Function

'@bfunc Get PUR On/Off value text from PUR enable value.
'@bparm PUR enable value
'@rdesc PUR On/Off value string
Public Function GetPUROnOffTextFromVal(PUREnableVal As Boolean) As String
    If PUREnableVal Then
        GetPUROnOffTextFromVal = "PUROn"
    Else
        GetPUROnOffTextFromVal = "PUROff"
    End If
End Function

'@bfunc get the detector reset value text from a reset value
'@bparm detector reset value
'@rdesc detector reset value text
'@flag intResetVal=0 | 13.1mS
'@flag intResetVal=1 | 6.55mS
'@flag intResetVal=2 | 3.28mS
'@flag intResetVal=3 | 1.64mS
'@flag intResetVal=4 | 819uS
'@flag intResetVal=5 | 410uS
'@flag intResetVal=6 | 205uS
'@flag intResetVal=7 | 102uS
'@flag intResetVal=8 | OFF
'@flag intResetVal=other values | Unknown
Public Function GetDetResetTextFromVal(intResetVal As Integer)
    Select Case intResetVal
        Case 0
            GetDetResetTextFromVal = "13.1mS"
        Case 1
            GetDetResetTextFromVal = "6.55mS"
        Case 2
            GetDetResetTextFromVal = "3.28mS"
        Case 3
            GetDetResetTextFromVal = "1.64mS"
        Case 4
            GetDetResetTextFromVal = "819uS"
        Case 5
            GetDetResetTextFromVal = "410uS"
        Case 6
            GetDetResetTextFromVal = "205uS"
        Case 7
            GetDetResetTextFromVal = "102uS"
        Case 8
            GetDetResetTextFromVal = "OFF"
        Case Else
            GetDetResetTextFromVal = "Unknown"
        End Select
End Function

'@bfunc get the baseline option control text from a reset value
'@bparm detector reset value
'@rdesc detector reset value text
'@flag intResetVal=0 | Slow
'@flag intResetVal=1 | Slow
'@flag intResetVal=2 | Slow
'@flag intResetVal=3 | Slow
'@flag intResetVal=4 | Fast
'@flag intResetVal=5 | Fast
'@flag intResetVal=6 | Fast
'@flag intResetVal=7 | Fast
'@flag intResetVal=8 | ---
'@flag intResetVal=other values | ---
Public Function GetBaselineOptTextFromVal(intResetVal As Integer) As String
    Select Case intResetVal
        Case 0
            GetBaselineOptTextFromVal = "Slow"
        Case 1
            GetBaselineOptTextFromVal = "Slow"
        Case 2
            GetBaselineOptTextFromVal = "Slow"
        Case 3
            GetBaselineOptTextFromVal = "Slow"
        Case 4
            GetBaselineOptTextFromVal = "Fast"
        Case 5
            GetBaselineOptTextFromVal = "Fast"
        Case 6
            GetBaselineOptTextFromVal = "Fast"
        Case 7
            GetBaselineOptTextFromVal = "Fast"
        Case 8
            GetBaselineOptTextFromVal = "---"
        Case Else
            GetBaselineOptTextFromVal = "---"
    End Select
End Function

'@bfunc get the DAC output option display string based on given DAC optionbox index
'@bparm DAC optionbox index
'@rdesc DAC output option string display text (shape name or off)
'@devnote This is used in clsDPPFile.CreateSaveFileHeader.
Public Function GetDACHeaderStrFromVal(DAC_EnableVal As Byte, DACVal As Integer) As String
    Dim strMsg As String
    Dim DACIndex As Integer
    DACIndex = GetDACOptIndexFromVal(DAC_EnableVal, DACVal)
    strMsg = ""
    Select Case DACIndex
        Case 0
            strMsg = strMsg & "Fast Channel"
        Case 1
            strMsg = strMsg & "Shaped Pulse"
        Case 2
            strMsg = strMsg & "Decimated Input"
        Case 3
            strMsg = strMsg & "Test"
        Case 4
            strMsg = strMsg & "Off"
        Case Else
            strMsg = strMsg & "unknown"
    End Select
    GetDACHeaderStrFromVal = strMsg
End Function

'@bfunc get the DAC output option control index given DAC values
'@bparm DAC Enabled value
'@bparm DAC output type value
'@rdesc DAC output option control index
Public Function GetDACOptIndexFromVal(DAC_EnableVal As Byte, DACVal As Integer) As Integer
    GetDACOptIndexFromVal = 4           'set default to off
    If Not CBool(DAC_EnableVal) Then           'if not enabled, set to off val(=4)
        GetDACOptIndexFromVal = 4
    ElseIf DACVal < 4 Then
        GetDACOptIndexFromVal = DACVal
    End If
End Function


'@bfunc Get Acq Mode value string from AcqMode value.
'@bparm AcqMode value
'@rdesc AcqMode value string
'@comm used in clsDPPFile.SaveConfigFile
Public Function GetAcqModeTextFromVal(AcqMode As Byte) As String
    GetAcqModeTextFromVal = Trim(IIf(CBool(AcqMode), "MCS", "MCA"))
End Function

Public Function GetInputPolarityString(InvertCG As Boolean)
    If (InvertCG) Then
        GetInputPolarityString = "Negative"
    Else
        GetInputPolarityString = "Positive"
    End If
End Function

'@bfunc Get MCA Channels String from MCAEnable and MCA Value
'@bparm MCAEnable Value
'@bparm MCA Value
'@rdesc string containing number of channels selected (without leading "MCA")
'@comm string used to display the number of channels, returns "Disable" if disabled
Public Function GetMCAChannelsStrFromVal(MCAEnableVal As Boolean, mcaVal As Integer) As String
    GetMCAChannelsStrFromVal = Trim(IIf(MCAEnableVal, CStr(((2 ^ (4 - mcaVal)) * 256)), "Disable"))
End Function

'@bfunc Get Port Selection value string from a port value.
'@bparm port value
'@rdesc Port Selection value string
Public Function GetPortStrFromVal(PortVal As Integer) As String
    'saves the comm port string COM
    'if port > 0 then is a ser com port, if = 0 then is USB, else not set
    GetPortStrFromVal = Trim(IIf(PortVal > 0, "COM" & Trim(CStr(PortVal)), IIf(PortVal = 0, "USB", "Port Not Set")))
End Function

'@bfunc Get RTD On/Off value string from RTD On/Off value.
'@bparm RTD On/Off value
'@rdesc RTD RTD On/Off value string
'@comm used in clsDPPFile.SaveConfigFile
Public Function GetRTDOnTextFromVal(RTDOnVal As Boolean) As String
    GetRTDOnTextFromVal = Trim(IIf(RTDOnVal, "RTDOn", "RTDOff"))
End Function

'@bfunc Get RTD Slow value string from RTD slow value.
'@bparm RTD slow value
'@rdesc RTD Slow value string
Public Function GetRTDSlowStrFromVal(RTDSlowVal As Byte) As String
    GetRTDSlowStrFromVal = FormatNumber((CDbl(RTDSlowVal * 100# / 512# * 100#) / 100#), 2) + "% FS"
End Function

'@bfunc Get RTD Fast value string from RTD fast value.
'@bparm RTD fast value
'@rdesc RTD Fast value string
Public Function GetRTDFastStrFromVal(RTDFastVal As Byte) As String
    GetRTDFastStrFromVal = CStr(RTDFastVal)
End Function

'@bfunc Get DP4 Analog Coarse Gain value text from a gain value.
'@bparm Gain Option index
'@rdesc DP4 Analog Coarse Gain value text
'@comm gain values are 0-3 (0=GAIN10,1=GAIN20,2=GAIN50,3=GAIN100)
Public Function GetAlogGainText(intAlogGain As Integer) As String
    Select Case intAlogGain
        Case 0
            GetAlogGainText = "GAIN10"
        Case 1
            GetAlogGainText = "GAIN20"
        Case 2
            GetAlogGainText = "GAIN50"
        Case 3
            GetAlogGainText = "GAIN100"
        Case Else
            GetAlogGainText = "GAIN not selected"
    End Select
End Function

Public Function GetCoarseGainString(CoarseGain As Integer, DppType As Integer)
    If DppType Then
        GetCoarseGainString = FormatNumber((4# * (1.2 ^ CoarseGain)), 2) & "x"
    Else
        Select Case CoarseGain
            Case 0
                GetCoarseGainString = "11x"
            Case 1
                GetCoarseGainString = "21x"
            Case 2
                GetCoarseGainString = "55x"
            Case 3
                GetCoarseGainString = "106x"
            Case Else
                GetCoarseGainString = "11x"
        End Select
    End If
End Function

Public Function GetFineGainString(FineGain As Integer)
    Dim dblTemp As Double
    dblTemp = CSng(FineGain) / CSng(8192)
    GetFineGainString = FormatNumber(dblTemp, 4)
End Function

'@bfunc get the BaselineOn Display string from baselineon value
'@bparm baselineon value
'@rdesc BaselineOn Display string
'@flag BaselineOnVal=False | AutoBaselineOff
'@flag BaselineOnVal=True | AutoBaselineOn
Public Function GetBaselineOnStrFromVal(BaselineOnVal As Boolean)
    ' the following were added in v3.4
    If BaselineOnVal Then
        GetBaselineOnStrFromVal = "AutoBaselineOn"
    Else
        GetBaselineOnStrFromVal = "AutoBaselineOff"
    End If
End Function

'@bfunc get the BaselineOn Display string from baselineon value
'@bparm baselineon value
'@rdesc BaselineOn Display string
'@flag BaselineOnVal=False | AutoBaselineOff
'@flag BaselineOnVal=True | AutoBaselineOn
Public Function GetBaselineOnStrFromValShort(BaselineOnVal As Boolean)
    ' the following were added in v3.4
    If BaselineOnVal Then
        GetBaselineOnStrFromValShort = "On"
    Else
        GetBaselineOnStrFromValShort = "Off"
    End If
End Function

'@bfunc Get the BLR display string from a BLR value
'@bparm BLR correction value
'@rdesc BLR display string
'@devnote See module notes for BLR correction settings.
'This function can be used to get a BLR correction string
'from a configuration value.
Public Function GetBLRStrFromVal(BLRVal As Byte) As String
    Dim strBLR As String

    If BLRVal = 63 Then
        strBLR = "BLR:OFF"
    Else
        strBLR = "BLR:ON "
        strBLR = strBLR & "DN:" & 4 ^ ((BLRVal And 48) / 16) & " " '(values 1,4,16,64)
        strBLR = strBLR & "UP:" & 4 ^ ((BLRVal And 12) / 4) & " "  '(values 1,4,16,64)
'        If (BLR And 3) > 1 Then     '(values 32,256,2048,16384)
        If (BLRVal And 3) > 1 Then     '(values 32,256,2048,16384)
            strBLR = strBLR & "TH:" & Int((32 * 8 ^ (BLRVal And 3)) / 1000) & "K"
        Else
            strBLR = strBLR & "TH:" & (32 * 8 ^ (BLRVal And 3))
        End If
    End If
    GetBLRStrFromVal = strBLR
End Function

'@bfunc get the buffer selection value display text from a buffer selection value
'@bparm buffer selection value
'@rdesc buffer selection value display text
Public Function GetBufferSelectValueString(ByVal BufferSelect As Integer) As String
    If BufferSelect = BufferSelectA Then
        GetBufferSelectValueString = "BufferSelectA"
    ElseIf BufferSelect = BufferSelectB Then
        GetBufferSelectValueString = "BufferSelectB"
    ElseIf BufferSelect = BufferSelectHW Then
        GetBufferSelectValueString = "BufferSelectHW"
    Else
        GetBufferSelectValueString = "BufferSelectA"
    End If
End Function

'@mfunc <c CDppBufferSel> get the buffer selection value display text from a buffer selection value
'@parm buffer selection value
'@rdesc buffer selection value display text
Public Function GetBufferSelectDispStr(BufferSelect As Byte) As String
    If (BufferSelect = BufferSelectA) Then
        GetBufferSelectDispStr = "Buffer A"
    ElseIf (BufferSelect = BufferSelectB) Then
        GetBufferSelectDispStr = "Buffer B"
    ElseIf (BufferSelect = BufferSelectHW) Then
        GetBufferSelectDispStr = "Buffer Hardware"
    Else
        GetBufferSelectDispStr = "Buffer None"
    End If
End Function

'@bfunc Get gate value string from a gate value.
'@bparm Gate value
'@rdesc gate value string
Public Function GetGateValueString(ByVal Gate As Integer) As String
    If Gate = 0 Then
        GetGateValueString = "GateOff"
    ElseIf Gate = 128 Then
        GetGateValueString = "GateHigh"
    ElseIf Gate = 192 Then
        GetGateValueString = "GateLow"
    Else
        GetGateValueString = "Gate not selected"
    End If
End Function

'@bfunc Get Preset Time value string from a preset time value.
'@bparm preset time value
'@rdesc Preset Time Control value string
Public Function GetPresetTimeStrFromVal(PresetVal As Long) As String
    Select Case PresetVal
        Case 0
            GetPresetTimeStrFromVal = "None"
        Case 10
            GetPresetTimeStrFromVal = "1 sec"
        Case 20
            GetPresetTimeStrFromVal = "2 sec"
        Case 50
            GetPresetTimeStrFromVal = "5 sec"
        Case 100
            GetPresetTimeStrFromVal = "10 sec"
        Case 300
            GetPresetTimeStrFromVal = "30 sec"
        Case 600
            GetPresetTimeStrFromVal = "1 min"
        Case 1200
            GetPresetTimeStrFromVal = "2 min"
        Case 3000
            GetPresetTimeStrFromVal = "5 min"
        Case 6000
            GetPresetTimeStrFromVal = "10 min"
        Case 18000
            GetPresetTimeStrFromVal = "30 min"
        Case 36000
            GetPresetTimeStrFromVal = "1 hr"
        Case 72000
            GetPresetTimeStrFromVal = "2 hr"
        Case 180000
            GetPresetTimeStrFromVal = "5 hr"
        Case 360000
            GetPresetTimeStrFromVal = "10 hr"
        Case 864000
            GetPresetTimeStrFromVal = "24 hr"
        Case Else
            GetPresetTimeStrFromVal = CLng(Val(PresetVal) / 10) & " sec"
    End Select
End Function

'this function puts spaces in strings to align description Text (Right)
'NOTE: needs fixed width font to display correctly
'^^^^^^^^^^^^Description :
Public Function TR(strStr As String, bufsize As Integer) As String
    Dim posStart As Long
    Dim posEnd As Long
    Dim strText As String
    Dim strBuffer As String
    Dim lenStr As Long
    Dim strDescr As String
    Dim remNL As Boolean        'flag, if text has vb nl as first chars don't remove (ie =false)
    Dim lenAdj As Long       'adjust the string search for increase in size due to alignment
    Dim strPre As String
    Dim strMid As String
    Dim strEnd As String
    Dim loopCntr As Integer
    
    'On Error GoTo trErr
    TR = strStr
    'If (InStr(1, strText, vbNewLine) = 1) Then
    If (InStr(1, strStr, vbNewLine) = 1) Then
        remNL = False
    Else
        strText = vbNewLine & strStr                    'append NL to string
        remNL = True                                    'will need to remove nl
    End If
    posStart = 1
    posEnd = 1
    lenStr = 0
    lenAdj = 0
    loopCntr = 0
    Do
        posStart = posStart + lenAdj
        posEnd = posEnd + lenAdj
        posStart = InStr(posEnd, strText, vbNewLine) + 2    'posStart at NL (2 chars)
        posEnd = InStr(posStart, strText, ":") + 1          'posEnd at ":"  (1 char)
        If (posEnd < 2) Then Exit Do
        lenStr = (posEnd - posStart) + 1
        lenAdj = bufsize - lenStr
        'strBuffer = Space(lenAdj)                           'create spaces buffer
        'strBuffer = String(lenAdj, "#")                           'create spaces buffer
        strBuffer = String(lenAdj, " ")                           'create spaces buffer
        strDescr = Mid(strText, posStart, lenStr)           'get string to be aligned
        
        strPre = Mid(strText, 1, posStart - 1)
        strMid = strBuffer & strDescr
        strEnd = Mid(strText, posEnd + 1)
        
        'insert string with buffer of spaces
        strText = strPre & strMid & strEnd
        If (loopCntr > 100) Then Exit Function  'exit if in infinite loop (won't do 100 lines)
    Loop While ((posEnd > 1) And (posEnd < Len(strText)))          'Loop Until ":" Not found
    
    
    If remNL Then strText = Mid(strText, 3) 'remove leading nl
    'MsgBox strText
    TR = strText
    Exit Function
trErr:
    'MsgBox Err.Description
    'exit without returning aligned string
End Function



' NOTE MCS Timebase control index=cfg value (the value doesn't need to be converted)
'@mfunc <c CDppAcqMode> Get MCS Timebase value string from a timebase value.
'@parm mcs timebase value
'@rdesc MCS Timebase Control value string
Public Function GetTimebaseStrFromIndex(TimebaseVal As Long) As String
    Select Case TimebaseVal
        Case 0
            GetTimebaseStrFromIndex = "10mS/channel"
        Case 1
            GetTimebaseStrFromIndex = "20mS/channel"
        Case 2
            GetTimebaseStrFromIndex = "50mS/channel"
        Case 3
            GetTimebaseStrFromIndex = "100mS/channel"
        Case 4
            GetTimebaseStrFromIndex = "200mS/channel"
        Case 5
            GetTimebaseStrFromIndex = "500mS/channel"
        Case 6
            GetTimebaseStrFromIndex = "1 sec/channel"
        Case 7
            GetTimebaseStrFromIndex = "2 sec/channel"
        Case 8
            GetTimebaseStrFromIndex = "5 sec/channel"
        Case 9
            GetTimebaseStrFromIndex = "10 sec/channel"
        Case 10
            GetTimebaseStrFromIndex = "20 sec/channel"
        Case 11
            GetTimebaseStrFromIndex = "30 sec/channel"
        Case 12
            GetTimebaseStrFromIndex = "60 sec/channel"
        Case 13
            GetTimebaseStrFromIndex = "90 sec/channel"
        Case 14
            GetTimebaseStrFromIndex = "120 sec/channel"
        Case 15
            GetTimebaseStrFromIndex = "300 sec/channel"
        Case Else
            GetTimebaseStrFromIndex = "1 sec/channel"
    End Select
End Function















































