﻿Imports System.Text

Public Class GraphOperation
    '----------------------------------------
    ' Global variable declaration
    '----------------------------------------
    Dim g_appid As Short    ' App access ID

    '================================================================================
    ' Initial settings
    '================================================================================
    Private Sub GraphOperation_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        '----------------------------------------
        ' Set the default button
        '----------------------------------------
        AcceptButton = Button_Close
        '----------------------------------------
        ' Create the combobox for window size
        '----------------------------------------
        ComboBox_OpenMode.Items.Add("Minimize")
        ComboBox_OpenMode.Items.Add("Normal")
        ComboBox_OpenMode.Items.Add("Maximize")
        '----------------------------------------
        ' Window size combobox selection
        '----------------------------------------
        ComboBox_OpenMode.SelectedIndex = LOGGER_PARAM_WINDOW_OFF
        '----------------------------------------
        ' Create the combobox for window operation
        '----------------------------------------
        ComboBox_WindowOperation.Items.Add("New")
        ComboBox_WindowOperation.Items.Add("Close")
        '----------------------------------------
        ' Window operation combobox selection
        '----------------------------------------
        ComboBox_WindowOperation.SelectedIndex = LOGGER_PARAM_GRAPH_OPEN
        '----------------------------------------
        ' Create the combobox for window operation target
        '----------------------------------------
        ComboBox_Target.Items.Add("File and Graph")
        ComboBox_Target.Items.Add("Graph")
        '----------------------------------------
        ' Window operation target combobox selection
        '----------------------------------------
        ComboBox_Target.SelectedIndex = LOGGER_PARAM_FILE
        '----------------------------------------
        ' Screen Capture - Create the combobox for save range
        '----------------------------------------
        ComboBox_ImageArea.Items.Add("Entire")
        ComboBox_ImageArea.Items.Add("YT Graph")
        '----------------------------------------
        ' Screen Capture - Save range combobox selection
        '----------------------------------------
        ComboBox_ImageArea.SelectedIndex = LOGGER_PARAM_AREA_ENTIRE
        '----------------------------------------
        ' Graph Resize - Create the combobox for axis
        '----------------------------------------
        ComboBox_ZoomAxis.Items.Add("X-axis")
        ComboBox_ZoomAxis.Items.Add("Y-axis")
        '----------------------------------------
        ' Graph Resize - Axis combobox selection
        '----------------------------------------
        ComboBox_ZoomAxis.SelectedIndex = LOGGER_PARAM_AXIS_X
        '----------------------------------------
        ' Graph Resize - Create the combobox for zoom
        '----------------------------------------
        ComboBox_Zoom.Items.Add("Zoom in(2x)")
        ComboBox_Zoom.Items.Add("Zoom out(x/2)")
        '----------------------------------------
        ' Graph Resize - Zoom combobox selection
        '----------------------------------------
        ComboBox_Zoom.SelectedIndex = LOGGER_PARAM_ZOOM_IN
        '----------------------------------------
        ' Graph Movement - Create the combobox for axis
        '----------------------------------------
        ComboBox_MoveAxis.Items.Add("X-axis")
        ComboBox_MoveAxis.Items.Add("Y-axis")
        '----------------------------------------
        ' Graph Movement - Axis combobox selection
        '----------------------------------------
        ComboBox_MoveAxis.SelectedIndex = LOGGER_PARAM_AXIS_X
        '----------------------------------------
        ' Graph Movement - Updated movement amount display
        '----------------------------------------
        TextBox_MoveDistance.Text = "1"
        '----------------------------------------
        ' Graph Movement - Create the combobox for movement direction
        '----------------------------------------
        ComboBox_MoveDirection.Items.Add("-")
        ComboBox_MoveDirection.Items.Add("+")
        '----------------------------------------
        ' Graph Movement - Movement direction combobox selection
        '----------------------------------------
        ComboBox_MoveDirection.SelectedIndex = 0
        '----------------------------------------
        ' Channel Information - Create the combobox for sequence number
        '----------------------------------------
        ComboBox_SequenceNo.Items.Add("0")
        ComboBox_SequenceNo.Items.Add("1")
        ComboBox_SequenceNo.Items.Add("2")
        ComboBox_SequenceNo.Items.Add("3")
        '----------------------------------------
        ' Channel Information - Sequence number combobox selection
        '----------------------------------------
        ComboBox_SequenceNo.SelectedIndex = 0
        '----------------------------------------
        ' Channel Information - Create the combobox for display
        '----------------------------------------
        ComboBox_ChannelEnable.Items.Add("Disable")
        ComboBox_ChannelEnable.Items.Add("Enable")
        '----------------------------------------
        ' Channel Information - Display combobox selection
        '----------------------------------------
        ComboBox_ChannelEnable.SelectedIndex = LOGGER_PARAM_DISABLE
        '----------------------------------------
        ' Channel Information - Create the combobox for Activation
        '----------------------------------------
        ComboBox_Activate.Items.Add("Disable")
        ComboBox_Activate.Items.Add("Enable")
        '----------------------------------------
        ' Channel Information - Activation combobox selection
        '----------------------------------------
        ComboBox_Activate.SelectedIndex = LOGGER_PARAM_DISABLE
        '----------------------------------------
        ' Channel Information - Create the combobox for dotted
        '----------------------------------------
        ComboBox_DisplayDot.Items.Add("Disable")
        ComboBox_DisplayDot.Items.Add("Enable")
        '----------------------------------------
        ' Channel Information - Dotted combobox selection
        '----------------------------------------
        ComboBox_DisplayDot.SelectedIndex = LOGGER_PARAM_DISABLE
        '----------------------------------------
        ' Channel Information - Create the combobox for time axis type
        '----------------------------------------
        ComboBox_TimeUnit.Items.Add("Absolute time")
        ComboBox_TimeUnit.Items.Add("Relative time")
        '----------------------------------------
        ' Channel Information - Time axis type combobox selection
        '----------------------------------------
        ComboBox_TimeUnit.SelectedIndex = LOGGER_PARAM_AXISTYPE_ABSOLUTE
        '----------------------------------------
        ' Channel Information - Create the combobox for decimal places
        '----------------------------------------
        ComboBox_Digit.Items.Add("0")
        ComboBox_Digit.Items.Add("1")
        ComboBox_Digit.Items.Add("2")
        ComboBox_Digit.Items.Add("3")
        ComboBox_Digit.Items.Add("4")
        ComboBox_Digit.Items.Add("5")
        '----------------------------------------
        ' Channel Information - Decimal places combobox selection
        '----------------------------------------
        ComboBox_Digit.SelectedIndex = 0
        '----------------------------------------
        ' Channel Information - Create the combobox for 2-split window
        '----------------------------------------
        ComboBox_Area2Enable.Items.Add("Disable")
        ComboBox_Area2Enable.Items.Add("Enable")
        '----------------------------------------
        ' Channel Information - 2-split window combobox selection
        '----------------------------------------
        ComboBox_Area2Enable.SelectedIndex = LOGGER_PARAM_DISABLE
        '----------------------------------------
        ' Channel Information - Create the combobox for Y-axis magnification display
        '----------------------------------------
        ComboBox_YAxisMagnificationEnable.Items.Add("Disable")
        ComboBox_YAxisMagnificationEnable.Items.Add("Enable")
        '----------------------------------------
        ' Channel Information - Y-axis magnification display combobox selection
        '----------------------------------------
        ComboBox_YAxisMagnificationEnable.SelectedIndex = LOGGER_PARAM_DISABLE
        '----------------------------------------
        ' Channel Information - Create the combobox for channel name library display
        '----------------------------------------
        ComboBox_ChannelDispEnable.Items.Add("Disable")
        ComboBox_ChannelDispEnable.Items.Add("Enable")
        '----------------------------------------
        ' Channel Information - Channel name library display combobox selection
        '----------------------------------------
        ComboBox_ChannelDispEnable.SelectedIndex = LOGGER_PARAM_DISABLE
        '----------------------------------------
        ' Channel Information - Create the combobox for graph auto-scroll
        '----------------------------------------
        ComboBox_AutoScrollEnable.Items.Add("Disable")
        ComboBox_AutoScrollEnable.Items.Add("Enable")
        '----------------------------------------
        ' Channel Information - Graph auto-scroll combobox selection
        '----------------------------------------
        ComboBox_AutoScrollEnable.SelectedIndex = LOGGER_PARAM_DISABLE
        '----------------------------------------
        ' Channel Information - Create the combobox for graph title
        '----------------------------------------
        ComboBox_TargetItem.Items.Add("X-axis")
        ComboBox_TargetItem.Items.Add("Y-axis")
        ComboBox_TargetItem.Items.Add("Graph title")
        '----------------------------------------
        ' Channel Information - Graph title combobox selection
        '----------------------------------------
        ComboBox_TargetItem.SelectedIndex = LOGGER_PARAM_AXIS_X
        '----------------------------------------
        ' Channel Information - Create the combobox for display
        '----------------------------------------
        ComboBox_TitleEnable.Items.Add("Disable")
        ComboBox_TitleEnable.Items.Add("Enable")
        '----------------------------------------
        ' Channel Information - Display combobox selection
        '----------------------------------------
        ComboBox_TitleEnable.SelectedIndex = LOGGER_PARAM_DISABLE
        '----------------------------------------
        ' Channel Information - Update graph title
        '----------------------------------------
        TextBox_TitleText.Text = "Graph title"
    End Sub

    '================================================================================
    ' This is the process that occurs when you click the LoggerLoadDataFile button
    ' Launch the app and enable access
    '================================================================================
    Private Sub Button_LoggerOpenApplication_Click(sender As Object, e As EventArgs) Handles Button_LoggerOpenApplication.Click
        Dim open_mode As UShort                           ' Screen size
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' Get screen size from combobox
        '----------------------------------------
        open_mode = ComboBox_OpenMode.SelectedIndex
        '----------------------------------------
        ' Initialize the app
        '----------------------------------------
        ret = LoggerOpenApplication("", g_appid, open_mode)
        '----------------------------------------
        ' Get error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display error code and message
        '----------------------------------------
        TextBox_ReturnNum.Text = "LoggerOpenApplication = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' This is the process that occurs when you click the ... button
    ' Displays the dialog to select the data file
    '================================================================================
    Private Sub Button_SelectDataFile_Click(sender As Object, e As EventArgs) Handles Button_SelectDataFile.Click
        '----------------------------------------
        ' Don't check if filename exists
        '----------------------------------------
        OpenFileDialog1.CheckFileExists = False
        '----------------------------------------
        ' If the path exists, set the current path to the initial path of dialog
        '----------------------------------------
        If TextBox_DataFilePath.Text.Length > 0 Then
            OpenFileDialog1.InitialDirectory = TextBox_DataFilePath.Text
            OpenFileDialog1.FileName = OpenFileDialog1.SafeFileName
            '----------------------------------------
            ' If the path not exists, set the MyDocuments path to the initial path of dialog
            '----------------------------------------
        Else
            OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            OpenFileDialog1.FileName = ""
        End If
        '----------------------------------------
        ' Display the selected path
        '----------------------------------------
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            TextBox_DataFilePath.Text = System.IO.Path.GetFullPath(OpenFileDialog1.FileName)
        End If
    End Sub

    '================================================================================
    ' This is the process that occurs when you click the LoggerLoadDataFile button
    ' Read the collected data
    '================================================================================
    Private Sub Button_LoggerLoadDataFile_Click(sender As Object, e As EventArgs) Handles Button_LoggerLoadDataFile.Click
        Dim file_path As String                           ' File path
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' Get file path from text box
        '----------------------------------------
        file_path = TextBox_DataFilePath.Text
        '----------------------------------------
        ' Loading the collected data
        '----------------------------------------
        ret = LoggerLoadDataFile(g_appid, file_path)
        '----------------------------------------
        ' Get error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display error code and message
        '----------------------------------------
        TextBox_ReturnNum.Text = "LoggerLoadDataFile = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' This is the process when the LoggerGraphWindowOperation button is clicked
    ' Operate the window
    '================================================================================
    Private Sub Button_LoggerGraphWindowOperation_Click(sender As Object, e As EventArgs) Handles Button_LoggerGraphWindowOperation.Click
        Dim target As UShort = LOGGER_PARAM_FILE                    ' For storing the target
        Dim window_operation As UShort = LOGGER_PARAM_GRAPH_OPEN    ' For storing window operations
        Dim error_string As New StringBuilder("", 256)              ' Error code string
        Dim ret As Integer                                          ' For return code

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' Get target from combobox
        '----------------------------------------
        target = ComboBox_Target.SelectedIndex
        '----------------------------------------
        ' Get window operation from combobox
        '----------------------------------------
        window_operation = ComboBox_WindowOperation.SelectedIndex
        '----------------------------------------
        ' Window operations
        '----------------------------------------
        ret = LoggerGraphWindowOperation(g_appid, window_operation, target, 0)
        '----------------------------------------
        ' Get error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display error code and message
        '----------------------------------------
        TextBox_ReturnNum.Text = "LoggerGraphWindowOperation = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' This is the process that occurs when you click the ... button
    ' Displays the dialog to select the image file
    '================================================================================
    Private Sub Button_SelectCaptureScreen_Click(sender As Object, e As EventArgs) Handles Button_SelectCaptureScreen.Click
        '----------------------------------------
        ' Don't check if filename exists
        '----------------------------------------
        OpenFileDialog1.CheckFileExists = False
        '----------------------------------------
        ' If the path exists, set the current path to the initial path of dialog
        '----------------------------------------
        If TextBox_CaptureScreenPath.Text.Length > 0 Then
            OpenFileDialog1.InitialDirectory = TextBox_DataFilePath.Text
            OpenFileDialog1.FileName = OpenFileDialog1.SafeFileName
            '----------------------------------------
            ' If the path not exists, set the MyDocuments path to the initial path of dialog
            '----------------------------------------
        Else
            OpenFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
            OpenFileDialog1.FileName = ""
        End If
        '----------------------------------------
        ' Display the selected path
        '----------------------------------------
        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            TextBox_CaptureScreenPath.Text = System.IO.Path.GetFullPath(OpenFileDialog1.FileName)
        End If
    End Sub

    '================================================================================
    ' This is the process that occurs when you click the LoggerCaptureScreen button
    ' Save the image
    '================================================================================
    Private Sub Button_LoggerCaptureScreen_Click(sender As Object, e As EventArgs) Handles Button_LoggerCaptureScreen.Click
        Dim file_path As String                                ' File path
        Dim image_area As UShort = LOGGER_PARAM_AREA_ENTIRE    ' For storing the storage range
        Dim error_string As New StringBuilder("", 256)         ' Error code string
        Dim ret As Integer                                     ' For return code

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' Get file path from textbox
        '----------------------------------------
        file_path = TextBox_CaptureScreenPath.Text
        '----------------------------------------
        ' Get the saved range from the combobox
        '----------------------------------------
        image_area = ComboBox_ImageArea.SelectedIndex
        '----------------------------------------
        ' Save image
        '----------------------------------------
        ret = LoggerCaptureScreen(g_appid, 0, image_area, file_path)
        '----------------------------------------
        ' Get error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display error code and message
        '----------------------------------------
        TextBox_ReturnNum.Text = "LoggerCaptureScreen = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' This is the process that occurs when the LoggerSetGraphZoom button is clicked
    ' Zoom the graph
    '================================================================================
    Private Sub Button_LoggerSetGraphZoom_Click(sender As Object, e As EventArgs) Handles Button_LoggerSetGraphZoom.Click
        Dim axis As UShort = LOGGER_PARAM_AXIS_X          ' For storing the axis
        Dim zoom As UShort = 0                            ' For scaling storage
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' Get axis from combobox
        '----------------------------------------
        axis = ComboBox_ZoomAxis.SelectedIndex
        '----------------------------------------
        ' Get scaling from combobox
        '----------------------------------------
        zoom = ComboBox_Zoom.SelectedIndex
        '----------------------------------------
        ' Zoom the graph
        '----------------------------------------
        ret = LoggerSetGraphZoom(g_appid, 0, axis, zoom)
        '----------------------------------------
        ' Get error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display error code and message
        '----------------------------------------
        TextBox_ReturnNum.Text = "LoggerSetGraphZoom = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' This is the process that occurs when the LoggerMoveGraphPos button is clicked
    ' Move the graph
    '================================================================================
    Private Sub Button_LoggerMoveGraphPos_Click(sender As Object, e As EventArgs) Handles Button_LoggerMoveGraphPos.Click
        Dim axis As UShort = LOGGER_PARAM_AXIS_X          ' For storing the axis
        Dim distance As Integer = 0                       ' For storing movement amount
        Dim direction As Integer = 0                      ' For storing movement direction
        Dim status As UInteger = 0                        ' For storing status
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' Get axis from combobox
        '----------------------------------------
        axis = ComboBox_MoveAxis.SelectedIndex
        '----------------------------------------
        ' Get the movement amount from the textbox
        '----------------------------------------
        If (Integer.TryParse(TextBox_MoveDistance.Text, distance) = False) Then
            TextBox_ReturnNum.Text = "Movement amount acquisition error"
            Exit Sub
        End If
        '----------------------------------------
        ' Get the movement direction from the combobox
        '----------------------------------------
        direction = ComboBox_MoveDirection.SelectedIndex
        '----------------------------------------
        ' In the negative direction, the movement amount is converted to a negative value
        '----------------------------------------
        If direction = 0 Then
            distance = distance * (-1)
        End If
        '----------------------------------------
        ' Move the graph
        '----------------------------------------
        ret = LoggerMoveGraphPos(g_appid, 0, axis, distance, status)
        '----------------------------------------
        ' Get error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display error code and message
        '----------------------------------------
        TextBox_ReturnNum.Text = "LoggerMoveGraphPos = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' This is the process that occurs when you click the LoggerSetGraphChannel button
    ' Switch channel display
    '================================================================================
    Private Sub Button_LoggerSetGraphChannel_Click(sender As Object, e As EventArgs) Handles Button_LoggerSetGraphChannel.Click
        Dim sequence_no As UShort = 0                       ' For storing sequence number
        Dim channel_enable As UShort = 0                    ' For storing the display
        Dim activate As UShort = LOGGER_PARAM_DISABLE       ' For storing activation
        Dim display_dot As UShort = LOGGER_PARAM_DISABLE    ' For storing dot display
        Dim error_string As New StringBuilder("", 256)      ' Error code string
        Dim ret As Integer                                  ' For return code

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' Get the sequence number from the combobox (index)
        '----------------------------------------
        sequence_no = ComboBox_SequenceNo.SelectedIndex
        '----------------------------------------
        ' Get the display from the combobox
        '----------------------------------------
        channel_enable = ComboBox_ChannelEnable.SelectedIndex
        '----------------------------------------
        ' Get activation from combobox
        '----------------------------------------
        activate = ComboBox_Activate.SelectedIndex
        '----------------------------------------
        ' Get dot display from combobox
        '----------------------------------------
        display_dot = ComboBox_DisplayDot.SelectedIndex
        '----------------------------------------
        ' Switch channel display
        '----------------------------------------
        ret = LoggerSetGraphChannel(g_appid, 0, sequence_no, channel_enable, activate, display_dot)
        '----------------------------------------
        ' Get error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display error code and message
        '----------------------------------------
        TextBox_ReturnNum.Text = "LoggerSetGraphChannel = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' This is the process that occurs when you click the LoggerSetGraph button
    ' Set the graph window detail
    '================================================================================
    Private Sub Button_LoggerSetGraph_Click(sender As Object, e As EventArgs) Handles Button_LoggerSetGraph.Click
        Dim time_unit As UShort = LOGGER_PARAM_AXISTYPE_ABSOLUTE            ' For storing time axis types
        Dim digit As UShort = 0                                             ' For storing the number of decimal places
        Dim area2_enable As UShort = LOGGER_PARAM_DISABLE                   ' For storing 2-split graph displays
        Dim y_axis_magnification_enable As UShort = LOGGER_PARAM_DISABLE    ' For storing the Y-axis magnification display
        Dim channel_disp_enable As UShort = LOGGER_PARAM_DISABLE            ' For storing channel name library displays
        Dim auto_scroll_enable As UShort = LOGGER_PARAM_DISABLE             ' For storing automatic graph scrolling
        Dim error_string As New StringBuilder("", 256)                      ' Error code string
        Dim ret As Integer                                                  ' For return code

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' Get the time axis type from the combobox
        '----------------------------------------
        time_unit = ComboBox_TimeUnit.SelectedIndex
        '----------------------------------------
        ' Get decimal places from combobox
        '----------------------------------------
        digit = ComboBox_Digit.SelectedIndex
        '----------------------------------------
        ' Get 2-split graph display from combobox
        '----------------------------------------
        area2_enable = ComboBox_Area2Enable.SelectedIndex
        '----------------------------------------
        ' Get Y-axis zoom from combobox
        '----------------------------------------
        y_axis_magnification_enable = ComboBox_YAxisMagnificationEnable.SelectedIndex
        '----------------------------------------
        ' Get channel name library display from combobox
        '----------------------------------------
        channel_disp_enable = ComboBox_ChannelDispEnable.SelectedIndex
        '----------------------------------------
        ' Get graph autoscroll from combobox
        '----------------------------------------
        auto_scroll_enable = ComboBox_AutoScrollEnable.SelectedIndex
        '----------------------------------------
        ' Set graph window detail
        '----------------------------------------
        ret = LoggerSetGraph(g_appid, 0, time_unit, digit, area2_enable, y_axis_magnification_enable, channel_disp_enable, auto_scroll_enable)
        '----------------------------------------
        ' Get error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display error code and message
        '----------------------------------------
        TextBox_ReturnNum.Text = "LoggerSetGraph = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' This is the process that occurs when you click the LoggerSetGraphLabelText button
    '
    '================================================================================
    Private Sub Button_LoggerSetGraphLabelText_Click(sender As Object, e As EventArgs) Handles Button_LoggerSetGraphLabelText.Click
        Dim target_item As UShort = LOGGER_PARAM_AXIS_X      ' For temporary text storage
        Dim title_enable As UShort = LOGGER_PARAM_DISABLE    ' For storing the display
        Dim title As String                                  ' Title
        Dim error_string As New StringBuilder("", 256)       ' Error code string
        Dim ret As Integer                                   ' For return code

        '----------------------------------------
        ' Update GUI information
        '----------------------------------------
        Me.Refresh()
        '----------------------------------------
        ' Get title axis from combobox
        '----------------------------------------
        target_item = ComboBox_TargetItem.SelectedIndex
        '----------------------------------------
        ' Get the display from the combobox
        '----------------------------------------
        title_enable = ComboBox_TitleEnable.SelectedIndex
        '----------------------------------------
        ' Get title from textbox
        '----------------------------------------
        title = TextBox_TitleText.Text
        '----------------------------------------
        ' Set graph window detail
        '----------------------------------------
        ret = LoggerSetGraphLabelText(g_appid, 0, target_item, title_enable, title)
        '----------------------------------------
        ' Get error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        '----------------------------------------
        ' Display error code and message
        '----------------------------------------
        TextBox_ReturnNum.Text = "LoggerSetGraphLabelText = " & ret & " : " & error_string.ToString()
    End Sub

    '================================================================================
    ' This is the process that occurs when the LoggerCloseApplication button is clicked
    ' Stop the app and disable access
    '================================================================================
    Private Sub Button_LoggerCloseApplication_Click(sender As Object, e As EventArgs) Handles Button_LoggerCloseApplication.Click
        Dim status As UInteger = LOGGER_STATUS_SUCCESS    ' For storing status
        Dim status_string As String                       ' Status display string
        Dim error_string As New StringBuilder("", 256)    ' Error code string
        Dim ret As Integer                                ' For return code

        '----------------------------------------
        ' The app is stopped and cannot be accessed
        '----------------------------------------
        ret = LoggerCloseApplication(g_appid, status)
        '----------------------------------------
        ' Get error string
        '----------------------------------------
        LoggerGetErrorString(ret, error_string)
        If ret <> 0 Then
            '----------------------------------------
            ' Display error code and message
            '----------------------------------------
            TextBox_ReturnNum.Text = String.Format("LoggerCloseApplication = {0} : {1}", ret, error_string)
        End If
        '----------------------------------------
        ' Get status string
        '----------------------------------------
        If status = LOGGER_STATUS_SUCCESS Then
            status_string = "Successful completion"
        ElseIf status = LOGGER_STATUS_FAILURE Then
            status_string = "C-LOGGER exit error"
        Else
            status_string = "Unknown status"
        End If
        '----------------------------------------
        ' Display error code and message
        '----------------------------------------
        TextBox_ReturnNum.Text = "LoggerCloseApplication = " & ret & " : " & error_string.ToString() & vbCrLf & "status = " & status & " : " & status_string
    End Sub

    '================================================================================
    ' This is the process that occurs when the Close button is clicked
    ' Terminate the application
    '================================================================================
    Private Sub Button_Close_Click(sender As Object, e As EventArgs) Handles Button_Close.Click
        Dim status As UInteger = 0                        ' For status storage

        '----------------------------------------
        ' Close the file(Considering that C-LOGGER may have exited, do not check the result)
        '----------------------------------------
        LoggerGraphWindowOperation(g_appid, CType(LOGGER_PARAM_GRAPH_CLOSE, UShort), CType(LOGGER_PARAM_FILE, UShort), 0)
        '----------------------------------------
        ' Stop the application and disable access
        '----------------------------------------
        LoggerCloseApplication(g_appid, status)
        '----------------------------------------
        ' Exit the dialog
        '----------------------------------------
        Me.Close()
    End Sub
End Class
