﻿Imports System.Text

Public Class ChannelSetting
    '----------------------------------------
    ' Macro definition
    '----------------------------------------
    Public Const SEQUENCE_NUM As Integer = 4
    '----------------------------------------
    ' Declaration of global variables
    '----------------------------------------
    Dim m_InputType As UShort
    Dim m_AiChannels As UShort
    Dim m_ChannelNo(SEQUENCE_NUM - 1) As UShort
    Dim m_ChName(SEQUENCE_NUM * 256 - 1) As Byte
    Dim m_Range(SEQUENCE_NUM - 1) As UShort
    Dim m_ScaleEnable(SEQUENCE_NUM - 1) As UShort
    Dim m_MinData(SEQUENCE_NUM - 1) As Single
    Dim m_MaxData(SEQUENCE_NUM - 1) As Single
    Dim m_MinScale(SEQUENCE_NUM - 1) As Single
    Dim m_MaxScale(SEQUENCE_NUM - 1) As Single
    Dim m_combobox_Hwch(SEQUENCE_NUM - 1) As ComboBox
    Dim m_combobox_Range(SEQUENCE_NUM - 1) As ComboBox
    Dim m_textbox_Chname(SEQUENCE_NUM - 1) As TextBox
    Dim m_textbox_MinData(SEQUENCE_NUM - 1) As TextBox
    Dim m_textbox_MaxData(SEQUENCE_NUM - 1) As TextBox
    Dim m_textbox_MinScale(SEQUENCE_NUM - 1) As TextBox
    Dim m_textbox_MaxScale(SEQUENCE_NUM - 1) As TextBox
    Dim m_combobox_ScaleEnable(SEQUENCE_NUM - 1) As ComboBox
    Dim g_ai_range() As Short = New Short() {PM10,        ' +/-10V
                                             PM5,         ' +/-5V
                                             PM25,        ' +/-2.5V
                                             PM125,       ' +/-1.25V
                                             P10,         ' 0-10V
                                             P5,          ' 0-5V
                                             P25,         ' 0-2.5V
                                             P125,        ' 0-1.25V
                                             P20MA,       ' 0-20mA
                                             P4TO20MA,    ' 4-20mA
                                             PM20MA,      ' +/-20mA
                                             P1TO5}       ' 1-5V
    '----------------------------------------
    ' Pass the data (Set)
    '----------------------------------------
    Public Sub channel_data_set(ByVal InputType As UShort,
                            ByVal AiChannels As UShort,
                            ByVal ChannelNo As UShort(),
                            ByVal ChName As Byte(),
                            ByVal Range As UShort(),
                            ByVal ScaleEnable As UShort(),
                            ByVal MinData As Single(),
                            ByVal MaxData As Single(),
                            ByVal MinScale As Single(),
                            ByVal MaxScale As Single())
        m_InputType = InputType
        m_AiChannels = AiChannels
        m_ChannelNo = ChannelNo
        m_ChName = ChName
        m_Range = Range
        m_ScaleEnable = ScaleEnable
        m_MinData = MinData
        m_MaxData = MaxData
        m_MinScale = MinScale
        m_MaxScale = MaxScale
    End Sub
    '----------------------------------------
    ' Pass the data (Get)
    '----------------------------------------
    Public Sub channel_data_get(ByRef InputType As UShort,
                            ByRef AiChannels As UShort,
                            ByRef ChannelNo() As UShort,
                            ByRef ChName As Byte(),
                            ByRef Range() As UShort,
                            ByRef ScaleEnable() As UShort,
                            ByRef MinData() As Single,
                            ByRef MaxData() As Single,
                            ByRef MinScale() As Single,
                            ByRef MaxScale() As Single)
        InputType = m_InputType
        AiChannels = m_AiChannels
        ChannelNo = m_ChannelNo
        ChName = m_ChName
        Range = m_Range
        ScaleEnable = m_ScaleEnable
        MinData = m_MinData
        MaxData = m_MaxData
        MinScale = m_MinScale
        MaxScale = m_MaxScale
    End Sub

    Private Sub ChannelSetting_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim ai_range_index As Integer    ' Index of analog input range

        '----------------------------------------
        ' Initialization of control array
        '----------------------------------------
        For i As Integer = 0 To SEQUENCE_NUM - 1
            Select Case i
                Case 0
                    m_combobox_Hwch(i) = ComboBox_HWch1
                    m_combobox_Range(i) = ComboBox_Range1
                    m_textbox_Chname(i) = TextBox_ChName1
                    m_textbox_MinData(i) = TextBox_MinData1
                    m_textbox_MaxData(i) = TextBox_MaxData1
                    m_textbox_MinScale(i) = TextBox_MinScale1
                    m_textbox_MaxScale(i) = TextBox_MaxScale1
                    m_combobox_ScaleEnable(i) = ComboBox_ScaleEnable1
                Case 1
                    m_combobox_Hwch(i) = ComboBox_HWch2
                    m_combobox_Range(i) = ComboBox_Range2
                    m_textbox_Chname(i) = TextBox_ChName2
                    m_textbox_MinData(i) = TextBox_MinData2
                    m_textbox_MaxData(i) = TextBox_MaxData2
                    m_textbox_MinScale(i) = TextBox_MinScale2
                    m_textbox_MaxScale(i) = TextBox_MaxScale2
                    m_combobox_ScaleEnable(i) = ComboBox_ScaleEnable2
                Case 2
                    m_combobox_Hwch(i) = ComboBox_HWch3
                    m_combobox_Range(i) = ComboBox_Range3
                    m_textbox_Chname(i) = TextBox_ChName3
                    m_textbox_MinData(i) = TextBox_MinData3
                    m_textbox_MaxData(i) = TextBox_MaxData3
                    m_textbox_MinScale(i) = TextBox_MinScale3
                    m_textbox_MaxScale(i) = TextBox_MaxScale3
                    m_combobox_ScaleEnable(i) = ComboBox_ScaleEnable3
                Case 3
                    m_combobox_Hwch(i) = ComboBox_HWch4
                    m_combobox_Range(i) = ComboBox_Range4
                    m_textbox_Chname(i) = TextBox_ChName4
                    m_textbox_MinData(i) = TextBox_MinData4
                    m_textbox_MaxData(i) = TextBox_MaxData4
                    m_textbox_MinScale(i) = TextBox_MinScale4
                    m_textbox_MaxScale(i) = TextBox_MaxScale4
                    m_combobox_ScaleEnable(i) = ComboBox_ScaleEnable4
                Case Else
                    m_combobox_Hwch(i) = ComboBox_HWch1
                    m_combobox_Range(i) = ComboBox_Range1
                    m_textbox_Chname(i) = TextBox_ChName1
                    m_textbox_MinData(i) = TextBox_MinData1
                    m_textbox_MaxData(i) = TextBox_MaxData1
                    m_textbox_MinScale(i) = TextBox_MinScale1
                    m_textbox_MaxScale(i) = TextBox_MaxScale1
                    m_combobox_ScaleEnable(i) = ComboBox_ScaleEnable1
            End Select
        Next
        '----------------------------------------
        ' Create the combobox for input method
        '----------------------------------------
        ComboBox_InputMethod.Items.Add("Single-end input")
        ComboBox_InputMethod.Items.Add("Differential input")
        '----------------------------------------
        ' Update the selection of input method combobox
        '----------------------------------------
        ComboBox_InputMethod.SelectedIndex = m_InputType
        '----------------------------------------
        ' Reset the combobox for number of channles
        '----------------------------------------
        ComboBox_AiChannels.Items.Clear()
        '----------------------------------------
        ' Create the combobox for number of channles
        '----------------------------------------
        ComboBox_AiChannels.Items.Add("1")
        ComboBox_AiChannels.Items.Add("2")
        '----------------------------------------
        ' For single-end input
        '----------------------------------------
        If m_InputType = LOGGER_PARAM_SINGLEENDED Then
            ComboBox_AiChannels.Items.Add("3")
            ComboBox_AiChannels.Items.Add("4")
        End If
        '----------------------------------------
        ' Update the selection of number of channles combobox(Number of channles - 1)
        '----------------------------------------
        If m_AiChannels > 0 Then
            ComboBox_AiChannels.SelectedIndex = m_AiChannels - 1
        Else
            ComboBox_AiChannels.SelectedIndex = 0
        End If
        '----------------------------------------
        ' Initialization of pointer array
        '----------------------------------------
        For i As Integer = 0 To SEQUENCE_NUM - 1
            '----------------------------------------
            ' Create the combobox for HWCh
            '----------------------------------------
            m_combobox_Hwch(i).Items.Add("0")
            m_combobox_Hwch(i).Items.Add("1")
            m_combobox_Hwch(i).Items.Add("2")
            m_combobox_Hwch(i).Items.Add("3")
            '----------------------------------------
            ' Update the selection of HWCh combobox
            '----------------------------------------
            m_combobox_Hwch(i).SelectedIndex = m_ChannelNo(i)
            '----------------------------------------
            ' Update the display of channel name
            '----------------------------------------
            Dim startPos = i * 256
            Dim nullPos = Array.IndexOf(m_ChName, 0, startPos, 256)
            Dim copyLen = If(nullPos = -1, 256, nullPos - startPos)
            System.Text.Encoding.RegisterProvider(CodePagesEncodingProvider.Instance)
            m_textbox_Chname(i).Text = System.Text.Encoding.GetEncoding("shift_jis").GetString(m_ChName, startPos, copyLen)
            '----------------------------------------
            ' Create the combobox for analog input range
            '----------------------------------------
            m_combobox_Range(i).Items.Add("-10 - +10V")
            m_combobox_Range(i).Items.Add("-5 - +5V")
            m_combobox_Range(i).Items.Add("-2.5 - +2.5V")
            m_combobox_Range(i).Items.Add("-1.25 - +1.25V")
            m_combobox_Range(i).Items.Add("0 - +10V")
            m_combobox_Range(i).Items.Add("0 - +5V")
            m_combobox_Range(i).Items.Add("0 - +2.5V")
            m_combobox_Range(i).Items.Add("0 - +1.25V")
            m_combobox_Range(i).Items.Add("0 - +20mA")
            m_combobox_Range(i).Items.Add("4 - +20mA")
            m_combobox_Range(i).Items.Add("-20 - +20mA")
            m_combobox_Range(i).Items.Add("1 - +5V")
            '----------------------------------------
            ' Update the selection of analog input range combobox
            '----------------------------------------
            ai_range_index = 0
            For j As Integer = 0 To g_ai_range.Length - 1
                If m_Range(i) = g_ai_range(j) Then
                    ai_range_index = j
                    Exit For
                End If
            Next
            m_combobox_Range(i).SelectedIndex = ai_range_index
            '----------------------------------------
            ' Create the combobox for scale enable/disable
            '----------------------------------------
            m_combobox_ScaleEnable(i).Items.Add("Disable")
            m_combobox_ScaleEnable(i).Items.Add("Enable")
            '----------------------------------------
            ' Update the selection of scale enable/disable combobox
            '----------------------------------------
            m_combobox_ScaleEnable(i).SelectedIndex = m_ScaleEnable(i)
            '----------------------------------------
            ' Update the display of data 1
            '----------------------------------------
            m_textbox_MinData(i).Text = m_MinData(i).ToString()
            '----------------------------------------
            ' Update the display of data 2
            '----------------------------------------
            m_textbox_MaxData(i).Text = m_MaxData(i).ToString()
            '----------------------------------------
            ' Update the display of minimum scale
            '----------------------------------------
            m_textbox_MinScale(i).Text = m_MinScale(i).ToString()
            '----------------------------------------
            ' Update the display of maximum scale
            '----------------------------------------
            m_textbox_MaxScale(i).Text = m_MaxScale(i).ToString()
        Next
        '----------------------------------------
        ' Call the number of channels combobox change event to update the display
        '----------------------------------------
        Call ComboBox_AiChannels_SelectedIndexChanged(Nothing, Nothing)
    End Sub

    '================================================================================
    ' It is the process when the value of input method combobox is changed
    ' Check the setting value and change the setting range for the number of channels
    '================================================================================
    Private Sub ComboBox_InputMethod_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_InputMethod.SelectedIndexChanged
        Dim input_type As Integer    ' Input method
        '----------------------------------------
        ' Get the input method from combobox
        '----------------------------------------
        input_type = ComboBox_InputMethod.SelectedIndex
        '----------------------------------------
        ' Reset the number of channels combobox
        '----------------------------------------
        ComboBox_AiChannels.Items.Clear()
        '----------------------------------------
        ' Create the combobox for number of channels
        '----------------------------------------
        ComboBox_AiChannels.Items.Add("1")
        ComboBox_AiChannels.Items.Add("2")
        '----------------------------------------
        ' For single-end input
        '----------------------------------------
        If input_type = LOGGER_PARAM_SINGLEENDED Then
            ComboBox_AiChannels.Items.Add("3")
            ComboBox_AiChannels.Items.Add("4")
        End If
        '----------------------------------------
        ' Select the combobox for number of channels
        '----------------------------------------
        ComboBox_AiChannels.SelectedIndex = 0
        '----------------------------------------
        ' Call the number of channels combobox change event to update the display
        '----------------------------------------
        Call ComboBox_AiChannels_SelectedIndexChanged(Nothing, Nothing)
    End Sub

    '================================================================================
    ' It is the process when the value of number of channels combobox is changed
    ' Check the setting value and enable/disable setting operations that are less than the number of channels
    '================================================================================
    Private Sub ComboBox_AiChannels_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_AiChannels.SelectedIndexChanged
        Dim scale_enable As Integer                  ' Scale conversion
        Dim i As Integer                             ' Loop count
        Dim sequence(SEQUENCE_NUM - 1) As Boolean    ' Sequence enable/disable
        Dim ai_channels As UShort                    ' Number of channels

        '----------------------------------------
        ' Get the number of channels from combobox(index + 1)
        '----------------------------------------
        ai_channels = CUShort(ComboBox_AiChannels.SelectedIndex + 1)
        '----------------------------------------
        ' Loop with the number of sequences
        '----------------------------------------
        For i = 0 To SEQUENCE_NUM - 1
            '----------------------------------------
            ' Disable settings that are less than the number of channels
            '----------------------------------------
            If i < ai_channels Then
                sequence(i) = True
            Else
                sequence(i) = False
            End If
            m_combobox_Hwch(i).Enabled = sequence(i)
            m_combobox_Range(i).Enabled = sequence(i)
            m_textbox_Chname(i).Enabled = sequence(i)
            m_combobox_ScaleEnable(i).Enabled = sequence(i)
            '----------------------------------------
            ' Disable the scale setting operation
            '----------------------------------------
            If sequence(i) = True Then
                scale_enable = m_combobox_ScaleEnable(i).SelectedIndex
                If scale_enable = LOGGER_PARAM_DISABLE Then
                    m_textbox_MinData(i).Enabled = False
                    m_textbox_MaxData(i).Enabled = False
                    m_textbox_MinScale(i).Enabled = False
                    m_textbox_MaxScale(i).Enabled = False
                ElseIf scale_enable = LOGGER_PARAM_ENABLE Then
                    m_textbox_MinData(i).Enabled = True
                    m_textbox_MaxData(i).Enabled = True
                    m_textbox_MinScale(i).Enabled = True
                    m_textbox_MaxScale(i).Enabled = True
                Else
                    m_textbox_MinData(i).Enabled = True
                    m_textbox_MaxData(i).Enabled = True
                    m_textbox_MinScale(i).Enabled = True
                    m_textbox_MaxScale(i).Enabled = True
                End If
            Else
                m_textbox_MinData(i).Enabled = sequence(i)
                m_textbox_MaxData(i).Enabled = sequence(i)
                m_textbox_MinScale(i).Enabled = sequence(i)
                m_textbox_MaxScale(i).Enabled = sequence(i)
            End If
        Next
    End Sub

    '================================================================================
    ' It is the process when the value of scale conversion combobox is changed
    ' Check the setting value and enable/disable the scale settings
    '================================================================================
    Private Sub ComboBox_ScaleEnable1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_ScaleEnable1.SelectedIndexChanged
        Dim scale_enable As Integer    ' Scale conversion

        '----------------------------------------
        ' Get the scale conversion
        '----------------------------------------
        scale_enable = ComboBox_ScaleEnable1.SelectedIndex
        If scale_enable = LOGGER_PARAM_DISABLE Then
            '----------------------------------------
            ' Disable
            '----------------------------------------
            TextBox_MinData1.Enabled = False
            TextBox_MaxData1.Enabled = False
            TextBox_MinScale1.Enabled = False
            TextBox_MaxScale1.Enabled = False
        ElseIf scale_enable = LOGGER_PARAM_ENABLE Then
            '----------------------------------------
            ' Enable
            '----------------------------------------
            TextBox_MinData1.Enabled = True
            TextBox_MaxData1.Enabled = True
            TextBox_MinScale1.Enabled = True
            TextBox_MaxScale1.Enabled = True
        Else
            '----------------------------------------
            ' Enable
            '----------------------------------------
            TextBox_MinData1.Enabled = True
            TextBox_MaxData1.Enabled = True
            TextBox_MinScale1.Enabled = True
            TextBox_MaxScale1.Enabled = True
        End If
    End Sub

    '================================================================================
    ' It is the process when the value of scale conversion combobox is changed
    ' Check the setting value and enable/disable the scale settings
    '================================================================================
    Private Sub ComboBox_ScaleEnable2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_ScaleEnable2.SelectedIndexChanged
        Dim scale_enable As Integer    ' Scale conversion

        '----------------------------------------
        ' Get the scale conversion
        '----------------------------------------
        scale_enable = ComboBox_ScaleEnable2.SelectedIndex
        If scale_enable = LOGGER_PARAM_DISABLE Then
            '----------------------------------------
            ' Disable
            '----------------------------------------
            TextBox_MinData2.Enabled = False
            TextBox_MaxData2.Enabled = False
            TextBox_MinScale2.Enabled = False
            TextBox_MaxScale2.Enabled = False
        ElseIf scale_enable = LOGGER_PARAM_ENABLE Then
            '----------------------------------------
            ' Enable
            '----------------------------------------
            TextBox_MinData2.Enabled = True
            TextBox_MaxData2.Enabled = True
            TextBox_MinScale2.Enabled = True
            TextBox_MaxScale2.Enabled = True
        Else
            '----------------------------------------
            ' Enable
            '----------------------------------------
            TextBox_MinData2.Enabled = True
            TextBox_MaxData2.Enabled = True
            TextBox_MinScale2.Enabled = True
            TextBox_MaxScale2.Enabled = True
        End If
    End Sub

    '================================================================================
    ' It is the process when the value of scale conversion combobox is changed
    ' Check the setting value and enable/disable the scale settings
    '================================================================================
    Private Sub ComboBox_ScaleEnable3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_ScaleEnable3.SelectedIndexChanged
        Dim scale_enable As Integer    ' Scale conversion

        '----------------------------------------
        ' Get the scale conversion
        '----------------------------------------
        scale_enable = ComboBox_ScaleEnable3.SelectedIndex
        If scale_enable = LOGGER_PARAM_DISABLE Then
            '----------------------------------------
            ' Disable
            '----------------------------------------
            TextBox_MinData3.Enabled = False
            TextBox_MaxData3.Enabled = False
            TextBox_MinScale3.Enabled = False
            TextBox_MaxScale3.Enabled = False
        ElseIf scale_enable = LOGGER_PARAM_ENABLE Then
            '----------------------------------------
            ' Enable
            '----------------------------------------
            TextBox_MinData3.Enabled = True
            TextBox_MaxData3.Enabled = True
            TextBox_MinScale3.Enabled = True
            TextBox_MaxScale3.Enabled = True
        Else
            '----------------------------------------
            ' Enable
            '----------------------------------------
            TextBox_MinData3.Enabled = True
            TextBox_MaxData3.Enabled = True
            TextBox_MinScale3.Enabled = True
            TextBox_MaxScale3.Enabled = True
        End If
    End Sub

    '================================================================================
    ' It is the process when the value of scale conversion combobox is changed
    ' Check the setting value and enable/disable the scale settings
    '================================================================================
    Private Sub ComboBox_ScaleEnable4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox_ScaleEnable4.SelectedIndexChanged
        Dim scale_enable As Integer   ' Scale conversion

        '----------------------------------------
        ' Get the scale conversion
        '----------------------------------------
        scale_enable = ComboBox_ScaleEnable4.SelectedIndex
        If scale_enable = LOGGER_PARAM_DISABLE Then
            '----------------------------------------
            ' Disable
            '----------------------------------------
            TextBox_MinData4.Enabled = False
            TextBox_MaxData4.Enabled = False
            TextBox_MinScale4.Enabled = False
            TextBox_MaxScale4.Enabled = False
        ElseIf scale_enable = LOGGER_PARAM_ENABLE Then
            '----------------------------------------
            ' Enable
            '----------------------------------------
            TextBox_MinData4.Enabled = True
            TextBox_MaxData4.Enabled = True
            TextBox_MinScale4.Enabled = True
            TextBox_MaxScale4.Enabled = True
        Else
            '----------------------------------------
            ' Enable
            '----------------------------------------
            TextBox_MinData4.Enabled = True
            TextBox_MaxData4.Enabled = True
            TextBox_MinScale4.Enabled = True
            TextBox_MaxScale4.Enabled = True
        End If
    End Sub

    '================================================================================
    ' It is the process when the Apply button is clicked
    ' Confirm the setting value
    '================================================================================
    Private Sub Button_Ok_Click(sender As Object, e As EventArgs) Handles Button_Ok.Click
        Dim pre_InputType As UShort                        ' For temporary storage  Input Method
        Dim pre_AiChannels As UShort                       ' For temporary storage  Number of channels
        Dim pre_ChannelNo(SEQUENCE_NUM - 1) As UShort      ' For temporary storage  Channel number
        Dim pre_ChName(SEQUENCE_NUM * 256 - 1) As Byte     ' For temporary storage  Channel name
        Dim pre_Range(SEQUENCE_NUM - 1) As UShort          ' For temporary storage  Range
        Dim pre_ScaleEnable(SEQUENCE_NUM - 1) As UShort    ' For temporary storage  Scale conversion enable/disable
        Dim pre_MinData(SEQUENCE_NUM - 1) As Single        ' For temporary storage  Minimum data
        Dim pre_MaxData(SEQUENCE_NUM - 1) As Single        ' For temporary storage  Maximum data
        Dim pre_MinScale(SEQUENCE_NUM - 1) As Single       ' For temporary storage  Minimum scale
        Dim pre_MaxScale(SEQUENCE_NUM - 1) As Single       ' For temporary storage  Maximum scale
        Dim i As Integer                                   ' Loop count
        Dim ai_range_index As Integer                      ' Index of analog input range

        '----------------------------------------
        ' Get the input method from combobox
        '----------------------------------------
        pre_InputType = CUShort(ComboBox_InputMethod.SelectedIndex)
        '----------------------------------------
        ' Get the number of channels from combobox(index + 1)
        '----------------------------------------
        pre_AiChannels = CUShort(ComboBox_AiChannels.SelectedIndex + 1)
        For i = 0 To SEQUENCE_NUM - 1
            '----------------------------------------
            ' Get the HWch from combobox
            '----------------------------------------
            pre_ChannelNo(i) = CUShort(m_combobox_Hwch(i).SelectedIndex)
            '----------------------------------------
            ' Get the range from combobox
            '----------------------------------------
            ai_range_index = m_combobox_Range(i).SelectedIndex
            pre_Range(i) = g_ai_range(ai_range_index)
            '----------------------------------------
            ' Get the channel name from textbox
            '----------------------------------------
            Dim bytes = System.Text.Encoding.GetEncoding("shift_jis").GetBytes(m_textbox_Chname(i).Text)
            Dim startPos = i * 256
            Dim copyLen = If((bytes.Length > 256), 256, bytes.Length)
            Array.Clear(pre_ChName, startPos, 256)
            Array.Copy(bytes, 0, pre_ChName, startPos, copyLen)
            '----------------------------------------
            ' Get the scale enable/disable from combobox
            '----------------------------------------
            pre_ScaleEnable(i) = CUShort(m_combobox_ScaleEnable(i).SelectedIndex)
            '----------------------------------------
            ' Get the data 1 from textbox
            '----------------------------------------
            If Single.TryParse(m_textbox_MinData(i).Text, pre_MinData(i)) = False Then
                pre_MinData(i) = 0
            End If
            '----------------------------------------
            ' Get the data 2 from textbox
            '----------------------------------------
            If Single.TryParse(m_textbox_MaxData(i).Text, pre_MaxData(i)) = False Then
                pre_MaxData(i) = 0
            End If
            '----------------------------------------
            ' Get the minimum scale from textbox
            '----------------------------------------
            If Single.TryParse(m_textbox_MinScale(i).Text, pre_MinScale(i)) = False Then
                pre_MinScale(i) = 0
            End If
            '----------------------------------------
            ' Get the maximum scale from textbox
            '----------------------------------------
            If Single.TryParse(m_textbox_MaxScale(i).Text, pre_MaxScale(i)) = False Then
                pre_MaxScale(i) = 0
            End If
        Next
        '----------------------------------------
        ' Copy from temporary storage to member variable
        '----------------------------------------
        m_InputType = pre_InputType
        m_AiChannels = pre_AiChannels
        m_ChannelNo = pre_ChannelNo
        m_ChName = pre_ChName
        m_Range = pre_Range
        m_ScaleEnable = pre_ScaleEnable
        m_MinData = pre_MinData
        m_MaxData = pre_MaxData
        m_MinScale = pre_MinScale
        m_MaxScale = pre_MaxScale

        Me.DialogResult = DialogResult.OK
        Me.Close()
    End Sub

    '================================================================================
    ' It is the process when the Cancel button is clicked
    '================================================================================
    Private Sub Button_Cancel_Click(sender As Object, e As EventArgs) Handles Button_Cancel.Click
        Me.Close()
    End Sub
End Class