﻿Public Class OrgSet

    Private Sub chkLimTurn_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkLimTurn.Click

        If chkLimTurn.CheckState = 1 Then
            LimitTurn = 1
        ElseIf chkLimTurn.CheckState = 0 Then
            LimitTurn = 0
        End If

    End Sub

    Private Sub chkOrg_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkOrg.Click

        If chkOrg.CheckState = 1 Then
            txtOrg.Text = "Low Active"
            OrgLog = OrgLog Xor &H1
        ElseIf chkOrg.CheckState = 0 Then
            txtOrg.Text = "High Active"
            OrgLog = OrgLog Or &H1
        End If

    End Sub

    Private Sub chkZ_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkZ.Click

        If chkZ.CheckState = 1 Then
            txtZ.Text = "Low Active"
            OrgLog = OrgLog Xor &H2
        ElseIf chkZ.CheckState = 0 Then
            txtZ.Text = "High Active"
            OrgLog = OrgLog Or &H2
        End If

    End Sub

    Private Sub chkZUse_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkZUse.Click

        If chkZUse.CheckState = 1 Then
            cboZCount.Enabled = True
            OrgType = 1
        ElseIf chkZUse.CheckState = 0 Then
            cboZCount.Enabled = False
            OrgType = 0
        End If

    End Sub

    Private Sub cboZCount_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboZCount.SelectedIndexChanged

        ZCount = cboZCount.SelectedIndex + 1

    End Sub



    Private Sub btnComReturn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnComReturn.Click

        Me.Close()

    End Sub

    Private Sub OrgSet_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Dim n As Short

        If OrgType = 0 Then
            chkZUse.CheckState = 0
        Else
            chkZUse.CheckState = 1
        End If
        chkZUse_Click(sender, e)

        ' ZCount ComboBox
        cboZCount.Items.Clear()
        For n = 1 To 16
            cboZCount.Items.Add(Str(n))
        Next

        ' ComboBox Initialise
        cboZCount.SelectedIndex = ZCount - 1

        ' EndDir OptionButton
        rdoDirDisable.Checked = False
        rdoPlusDir.Checked = False
        rdoMinusDir.Checked = False
        Select Case EndDir
            Case 0
                rdoDirDisable.Checked = True
            Case 1
                rdoPlusDir.Checked = True
            Case 2
                rdoMinusDir.Checked = True
        End Select

        ' OrgLog CheckBox
        If (OrgLog And &H1) Then
            chkOrg.CheckState = 0
        End If

        If (OrgLog And &H2) Then
            chkZ.CheckState = 0
        End If

        ' LimitTurn CheckBox
        ' CheckBox Initialise
        chkLimTurn.Checked = LimitTurn

    End Sub

    Private Sub rdoDirDisable_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoDirDisable.Click

        EndDir = 0

    End Sub

    Private Sub rdoPlusDir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoPlusDir.Click

        EndDir = 1

    End Sub

    Private Sub rdoMinusDir_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles rdoMinusDir.Click

        EndDir = 2

    End Sub
End Class