Option Strict Off
Option Explicit On 
Public Class Comp
    Inherits System.Windows.Forms.Form

#Region " Windows tH[ fUCiŐꂽR[h "

    Public Sub New()
        MyBase.New()

        ' ̌Ăяo Windows tH[ fUCiŕKvłB
        InitializeComponent()

        ' InitializeComponent() Ăяǒɏǉ܂B

    End Sub

    ' Form  dispose I[o[ChăR|[lgꗗ܂B
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    ' Windows tH[ fUCiŕKvłB
    Private components As System.ComponentModel.IContainer

    '  : ȉ̃vV[ẂAWindows tH[ fUCiŕKvłB
    ' Windows tH[ fUCigĕύXĂB  
    ' R[h GfB^͎gpȂłB
	Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
	Friend WithEvents Label11 As System.Windows.Forms.Label
	Friend WithEvents Label7 As System.Windows.Forms.Label
	Friend WithEvents Label10 As System.Windows.Forms.Label
	Friend WithEvents Label9 As System.Windows.Forms.Label
	Friend WithEvents Label8 As System.Windows.Forms.Label
	Friend WithEvents Label6 As System.Windows.Forms.Label
	Friend WithEvents Label5 As System.Windows.Forms.Label
	Friend WithEvents Label4 As System.Windows.Forms.Label
	Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
	Friend WithEvents Label1 As System.Windows.Forms.Label
	Friend WithEvents Label2 As System.Windows.Forms.Label
	Friend WithEvents txtComp7 As System.Windows.Forms.TextBox
	Friend WithEvents txtComp6 As System.Windows.Forms.TextBox
	Friend WithEvents txtComp5 As System.Windows.Forms.TextBox
	Friend WithEvents txtComp4 As System.Windows.Forms.TextBox
	Friend WithEvents txtComp3 As System.Windows.Forms.TextBox
	Friend WithEvents txtComp2 As System.Windows.Forms.TextBox
	Friend WithEvents txtComp1 As System.Windows.Forms.TextBox
	Friend WithEvents txtComp0 As System.Windows.Forms.TextBox
	Friend WithEvents rdoComp1 As System.Windows.Forms.RadioButton
	Friend WithEvents rdoComp0 As System.Windows.Forms.RadioButton
	Friend WithEvents txtPulse As System.Windows.Forms.TextBox
	Friend WithEvents btnOK As System.Windows.Forms.Button
	Friend WithEvents btnCancel As System.Windows.Forms.Button
	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
		Me.GroupBox1 = New System.Windows.Forms.GroupBox()
		Me.txtComp7 = New System.Windows.Forms.TextBox()
		Me.txtComp6 = New System.Windows.Forms.TextBox()
		Me.txtComp5 = New System.Windows.Forms.TextBox()
		Me.txtComp4 = New System.Windows.Forms.TextBox()
		Me.txtComp3 = New System.Windows.Forms.TextBox()
		Me.txtComp2 = New System.Windows.Forms.TextBox()
		Me.txtComp1 = New System.Windows.Forms.TextBox()
		Me.txtComp0 = New System.Windows.Forms.TextBox()
		Me.Label11 = New System.Windows.Forms.Label()
		Me.Label7 = New System.Windows.Forms.Label()
		Me.Label10 = New System.Windows.Forms.Label()
		Me.Label9 = New System.Windows.Forms.Label()
		Me.Label8 = New System.Windows.Forms.Label()
		Me.Label6 = New System.Windows.Forms.Label()
		Me.Label5 = New System.Windows.Forms.Label()
		Me.Label4 = New System.Windows.Forms.Label()
		Me.rdoComp1 = New System.Windows.Forms.RadioButton()
		Me.rdoComp0 = New System.Windows.Forms.RadioButton()
		Me.GroupBox2 = New System.Windows.Forms.GroupBox()
		Me.Label2 = New System.Windows.Forms.Label()
		Me.txtPulse = New System.Windows.Forms.TextBox()
		Me.Label1 = New System.Windows.Forms.Label()
		Me.btnOK = New System.Windows.Forms.Button()
		Me.btnCancel = New System.Windows.Forms.Button()
		Me.GroupBox1.SuspendLayout()
		Me.GroupBox2.SuspendLayout()
		Me.SuspendLayout()
		'
		'GroupBox1
		'
		Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.txtComp7, Me.txtComp6, Me.txtComp5, Me.txtComp4, Me.txtComp3, Me.txtComp2, Me.txtComp1, Me.txtComp0, Me.Label11, Me.Label7, Me.Label10, Me.Label9, Me.Label8, Me.Label6, Me.Label5, Me.Label4, Me.rdoComp1, Me.rdoComp0})
		Me.GroupBox1.Location = New System.Drawing.Point(22, 8)
		Me.GroupBox1.Name = "GroupBox1"
		Me.GroupBox1.Size = New System.Drawing.Size(210, 268)
		Me.GroupBox1.TabIndex = 0
		Me.GroupBox1.TabStop = False
		Me.GroupBox1.Text = "rWX^ݒ"
		'
		'txtComp7
		'
		Me.txtComp7.Location = New System.Drawing.Point(84, 232)
		Me.txtComp7.Name = "txtComp7"
		Me.txtComp7.TabIndex = 61
		Me.txtComp7.Text = ""
		'
		'txtComp6
		'
		Me.txtComp6.Location = New System.Drawing.Point(84, 208)
		Me.txtComp6.Name = "txtComp6"
		Me.txtComp6.TabIndex = 60
		Me.txtComp6.Text = ""
		'
		'txtComp5
		'
		Me.txtComp5.Location = New System.Drawing.Point(84, 184)
		Me.txtComp5.Name = "txtComp5"
		Me.txtComp5.TabIndex = 59
		Me.txtComp5.Text = ""
		'
		'txtComp4
		'
		Me.txtComp4.Location = New System.Drawing.Point(84, 160)
		Me.txtComp4.Name = "txtComp4"
		Me.txtComp4.TabIndex = 58
		Me.txtComp4.Text = ""
		'
		'txtComp3
		'
		Me.txtComp3.Location = New System.Drawing.Point(84, 136)
		Me.txtComp3.Name = "txtComp3"
		Me.txtComp3.TabIndex = 57
		Me.txtComp3.Text = ""
		'
		'txtComp2
		'
		Me.txtComp2.Location = New System.Drawing.Point(84, 112)
		Me.txtComp2.Name = "txtComp2"
		Me.txtComp2.TabIndex = 56
		Me.txtComp2.Text = ""
		'
		'txtComp1
		'
		Me.txtComp1.Location = New System.Drawing.Point(84, 88)
		Me.txtComp1.Name = "txtComp1"
		Me.txtComp1.TabIndex = 55
		Me.txtComp1.Text = ""
		'
		'txtComp0
		'
		Me.txtComp0.Location = New System.Drawing.Point(84, 64)
		Me.txtComp0.Name = "txtComp0"
		Me.txtComp0.TabIndex = 54
		Me.txtComp0.Text = ""
		'
		'Label11
		'
		Me.Label11.Location = New System.Drawing.Point(24, 240)
		Me.Label11.Name = "Label11"
		Me.Label11.Size = New System.Drawing.Size(48, 16)
		Me.Label11.TabIndex = 53
		Me.Label11.Text = "7"
		'
		'Label7
		'
		Me.Label7.Location = New System.Drawing.Point(24, 144)
		Me.Label7.Name = "Label7"
		Me.Label7.Size = New System.Drawing.Size(48, 16)
		Me.Label7.TabIndex = 49
		Me.Label7.Text = "3"
		'
		'Label10
		'
		Me.Label10.Location = New System.Drawing.Point(24, 216)
		Me.Label10.Name = "Label10"
		Me.Label10.Size = New System.Drawing.Size(48, 16)
		Me.Label10.TabIndex = 52
		Me.Label10.Text = "6"
		'
		'Label9
		'
		Me.Label9.Location = New System.Drawing.Point(24, 192)
		Me.Label9.Name = "Label9"
		Me.Label9.Size = New System.Drawing.Size(48, 16)
		Me.Label9.TabIndex = 51
		Me.Label9.Text = "5"
		'
		'Label8
		'
		Me.Label8.Location = New System.Drawing.Point(24, 168)
		Me.Label8.Name = "Label8"
		Me.Label8.Size = New System.Drawing.Size(48, 16)
		Me.Label8.TabIndex = 50
		Me.Label8.Text = "4"
		'
		'Label6
		'
		Me.Label6.Location = New System.Drawing.Point(24, 120)
		Me.Label6.Name = "Label6"
		Me.Label6.Size = New System.Drawing.Size(48, 16)
		Me.Label6.TabIndex = 48
		Me.Label6.Text = "2"
		'
		'Label5
		'
		Me.Label5.Location = New System.Drawing.Point(24, 96)
		Me.Label5.Name = "Label5"
		Me.Label5.Size = New System.Drawing.Size(48, 16)
		Me.Label5.TabIndex = 47
		Me.Label5.Text = "1"
		'
		'Label4
		'
		Me.Label4.Location = New System.Drawing.Point(24, 72)
		Me.Label4.Name = "Label4"
		Me.Label4.Size = New System.Drawing.Size(48, 16)
		Me.Label4.TabIndex = 46
		Me.Label4.Text = "0"
		'
		'rdoComp1
		'
		Me.rdoComp1.Location = New System.Drawing.Point(84, 44)
		Me.rdoComp1.Name = "rdoComp1"
		Me.rdoComp1.Size = New System.Drawing.Size(64, 16)
		Me.rdoComp1.TabIndex = 1
		Me.rdoComp1.Text = "16i"
		'
		'rdoComp0
		'
		Me.rdoComp0.Location = New System.Drawing.Point(84, 24)
		Me.rdoComp0.Name = "rdoComp0"
		Me.rdoComp0.Size = New System.Drawing.Size(64, 16)
		Me.rdoComp0.TabIndex = 0
		Me.rdoComp0.Text = "10i"
		'
		'GroupBox2
		'
		Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label2, Me.txtPulse, Me.Label1})
		Me.GroupBox2.Location = New System.Drawing.Point(22, 282)
		Me.GroupBox2.Name = "GroupBox2"
		Me.GroupBox2.Size = New System.Drawing.Size(210, 52)
		Me.GroupBox2.TabIndex = 1
		Me.GroupBox2.TabStop = False
		Me.GroupBox2.Text = "JEgvpXݒ"
		'
		'Label2
		'
		Me.Label2.Location = New System.Drawing.Point(173, 24)
		Me.Label2.Name = "Label2"
		Me.Label2.Size = New System.Drawing.Size(24, 16)
		Me.Label2.TabIndex = 2
		Me.Label2.Text = "Hex"
		'
		'txtPulse
		'
		Me.txtPulse.Location = New System.Drawing.Point(83, 20)
		Me.txtPulse.Name = "txtPulse"
		Me.txtPulse.Size = New System.Drawing.Size(85, 19)
		Me.txtPulse.TabIndex = 1
		Me.txtPulse.Text = ""
		'
		'Label1
		'
		Me.Label1.Location = New System.Drawing.Point(24, 24)
		Me.Label1.Name = "Label1"
		Me.Label1.Size = New System.Drawing.Size(64, 16)
		Me.Label1.TabIndex = 0
		Me.Label1.Text = "pXF"
		'
		'btnOK
		'
		Me.btnOK.Location = New System.Drawing.Point(22, 344)
		Me.btnOK.Name = "btnOK"
		Me.btnOK.Size = New System.Drawing.Size(96, 24)
		Me.btnOK.TabIndex = 2
		Me.btnOK.Text = "OK"
		'
		'btnCancel
		'
		Me.btnCancel.Location = New System.Drawing.Point(136, 344)
		Me.btnCancel.Name = "btnCancel"
		Me.btnCancel.Size = New System.Drawing.Size(96, 24)
		Me.btnCancel.TabIndex = 3
		Me.btnCancel.Text = "ݾ"
		'
		'Comp
		'
		Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
		Me.ClientSize = New System.Drawing.Size(256, 381)
		Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnCancel, Me.btnOK, Me.GroupBox2, Me.GroupBox1})
		Me.Font = New System.Drawing.Font("lr oSVbN", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
		Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
		Me.MaximizeBox = False
		Me.MinimizeBox = False
		Me.Name = "Comp"
		Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
		Me.Text = "rݒ"
		Me.GroupBox1.ResumeLayout(False)
		Me.GroupBox2.ResumeLayout(False)
		Me.ResumeLayout(False)

	End Sub

#End Region
    Dim Ret As Int32                            ' ߂l
    Dim szError As New System.Text.StringBuilder("", 256)   ' G[
	Dim szReturnCode As New String("", 256)		' \G[
	Dim szText As New String("", 100)			' e|
	Dim m_Comp(7) As TextBox					' rlRg[

    Dim CompValue(7) As Int32                  ' rl
    Dim PulseWidth As Int32                 ' pX

	'---------------------------------------------------------
	'	_CAO
	'---------------------------------------------------------
	Private Sub Comp_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

		'-----------------------------------
		' ʃACȅ
		'-----------------------------------
		Dim i As Short
		rdoComp0.Checked = True
		m_Comp(0) = txtComp0
		m_Comp(1) = txtComp1
		m_Comp(2) = txtComp2
		m_Comp(3) = txtComp3
		m_Comp(4) = txtComp4
		m_Comp(5) = txtComp5
		m_Comp(6) = txtComp6
		m_Comp(7) = txtComp7
		For i = 0 To 7
			If i >= ChannelNum Then
				m_Comp(i).Enabled = False
			End If
		Next i
		'-----------------------------------
		' JEgvpX̎擾ƕ\
		'-----------------------------------
        Dim PlsWidth As Int32
		Ret = CntGetPulseWidth(Id, 0, PlsWidth)
		If Ret <> CNT_ERR_SUCCESS Then
			PlsWidth = 0
		End If
		txtPulse.Text = Hex(PlsWidth)
		'-----------------------------------
		' JEgrl̎擾ƕ\
		'-----------------------------------
		For i = 0 To (ChannelNum - 1)
			CompValue(i) = 0
			Ret = CntGetCountMatchReg(Id, i, 0, CompValue(i))
			m_Comp(i).Text = String.Format("{0:d}", CompValue(i))
		Next i

	End Sub

	'---------------------------------------------------------
	'	OK{^̏
	'---------------------------------------------------------
	Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click

		Dim i As Short
		'-----------------------------------
		' ʂݒl擾
		'-----------------------------------
        For i = 0 To (ChannelNum - 1)
            szText = m_Comp(i).Text
            Try
                If rdoComp0.Checked = True Then
                    CompValue(i) = Integer.Parse(szText)
                Else
                    CompValue(i) = Integer.Parse(szText, System.Globalization.NumberStyles.HexNumber)
                End If
            Catch ex As Exception
                CompValue(i) = 0
            End Try

        Next i
		szText = txtPulse.Text
        PulseWidth = Integer.Parse(szText, System.Globalization.NumberStyles.HexNumber)
		'-----------------------------------
		' e`l
		'-----------------------------------
		For i = 0 To (ChannelNum - 1)
			'-----------------------------------
			' rlݒ
			'-----------------------------------
			Ret = CntSetCountMatchEvent(Id, i, 0, CompValue(i), 1)
			'-----------------------------
			' G[
			'-----------------------------
			If Ret <> CNT_ERR_SUCCESS Then
				CntGetErrorString(Ret, szError)
                szReturnCode = "CntSetCountMatchEvent : " & szError.ToString()
				MsgBox(szReturnCode, MsgBoxStyle.OKOnly, "G[")
				Exit Sub
			End If
			'-----------------------------------
			' pXݒ
			'-----------------------------------
			Ret = CntSetPulseWidth(Id, i, PulseWidth)
			'-----------------------------
			' G[
			'-----------------------------
			If Ret <> CNT_ERR_SUCCESS Then
				CntGetErrorString(Ret, szError)
                szReturnCode = "CntSetPulseWidth : " & szError.ToString()
				MsgBox(szReturnCode, MsgBoxStyle.OKOnly, "G[")
				Exit Sub
			End If
		Next i
		'-----------------------------------
		' pXݒ
		'-----------------------------------
		Me.Close()

	End Sub

	'---------------------------------------------------------
	'	LZ{^̏
	'---------------------------------------------------------
	Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

		Me.Close()

	End Sub

	'---------------------------------------------------------
	'	rl̕\ύX
	'---------------------------------------------------------
	'	10i
	Private Sub rdoComp0_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles rdoComp0.MouseDown

		'-----------------------------------
		' ʏXV
		'-----------------------------------
		Dim i As Short
		For i = 0 To 7
			szText = String.Format("{0:d}", CompValue(i))
			m_Comp(i).Text = szText
		Next i

	End Sub

	'	16i
	Private Sub rdoComp1_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles rdoComp1.MouseDown

		'-----------------------------------
		' ʏXV
		'-----------------------------------
		Dim i As Short
		For i = 0 To 7
			szText = String.Format("{0:X8}", CompValue(i))
			m_Comp(i).Text = szText
		Next i

	End Sub
End Class