Option Strict Off
Option Explicit On 
Imports System.Runtime.InteropServices
Friend Class Form1
	Inherits System.Windows.Forms.Form
#Region "Windows tH[ fUCiɂĐꂽR[h"
	Public Sub New()
		MyBase.New()
		If m_vb6FormDefInstance Is Nothing Then
			If m_InitializingDefInstance Then
				m_vb6FormDefInstance = Me
			Else
				Try 
					'X^[gAbv tH[ɂẮAŏɍ쐬ꂽCX^XCX^XɂȂ܂B
					If System.Reflection.Assembly.GetExecutingAssembly.EntryPoint.DeclaringType Is Me.GetType Then
						m_vb6FormDefInstance = Me
					End If
				Catch
				End Try
			End If
		End If
		'̌ĂяóAWindows tH[ fUCiŕKvłB
		InitializeComponent()
	End Sub
	'Form ́AR|[lgꗗɌ㏈s邽߂ dispose I[o[Ch܂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
	Public ToolTip1 As System.Windows.Forms.ToolTip
	Public WithEvents Exit_Renamed As System.Windows.Forms.Button
    Public WithEvents Initialize As System.Windows.Forms.Button
    Public WithEvents DelRet As System.Windows.Forms.Button
	Public WithEvents TextRet As System.Windows.Forms.TextBox
	Public WithEvents DelSts As System.Windows.Forms.Button
	Public WithEvents Polling As System.Windows.Forms.Button
	Public WithEvents PollSts As System.Windows.Forms.TextBox
	Public WithEvents YrAdrBox As System.Windows.Forms.ComboBox
	Public WithEvents MyAddress As System.Windows.Forms.TextBox
	Public WithEvents Label2 As System.Windows.Forms.Label
	Public WithEvents Label1 As System.Windows.Forms.Label
	Public WithEvents Frame1 As System.Windows.Forms.GroupBox
	Public WithEvents Label4 As System.Windows.Forms.Label
	Public WithEvents Label3 As System.Windows.Forms.Label
	' : ȉ̃vV[W Windows tH[ fUCiŕKvłB
	'Windows tH[ fUCigĕύXł܂B
	'R[hGfB^gďCȂłB


	<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
        Me.Exit_Renamed = New System.Windows.Forms.Button()
        Me.Initialize = New System.Windows.Forms.Button()
        Me.DelRet = New System.Windows.Forms.Button()
        Me.TextRet = New System.Windows.Forms.TextBox()
        Me.DelSts = New System.Windows.Forms.Button()
        Me.Polling = New System.Windows.Forms.Button()
        Me.PollSts = New System.Windows.Forms.TextBox()
        Me.Frame1 = New System.Windows.Forms.GroupBox()
        Me.YrAdrBox = New System.Windows.Forms.ComboBox()
        Me.MyAddress = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.Frame1.SuspendLayout()
        Me.SuspendLayout()
        '
        'Exit_Renamed
        '
        Me.Exit_Renamed.BackColor = System.Drawing.SystemColors.Control
        Me.Exit_Renamed.Cursor = System.Windows.Forms.Cursors.Default
        Me.Exit_Renamed.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.Exit_Renamed.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Exit_Renamed.Location = New System.Drawing.Point(414, 184)
        Me.Exit_Renamed.Name = "Exit_Renamed"
        Me.Exit_Renamed.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Exit_Renamed.Size = New System.Drawing.Size(121, 35)
        Me.Exit_Renamed.TabIndex = 8
        Me.Exit_Renamed.Text = "I(&X)"
        '
        'Initialize
        '
        Me.Initialize.BackColor = System.Drawing.SystemColors.Control
        Me.Initialize.Cursor = System.Windows.Forms.Cursors.Default
        Me.Initialize.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.Initialize.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Initialize.Location = New System.Drawing.Point(8, 184)
        Me.Initialize.Name = "Initialize"
        Me.Initialize.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Initialize.Size = New System.Drawing.Size(121, 35)
        Me.Initialize.TabIndex = 5
        Me.Initialize.Text = "(&I)"
        '
        'DelRet
        '
        Me.DelRet.BackColor = System.Drawing.SystemColors.Control
        Me.DelRet.Cursor = System.Windows.Forms.Cursors.Default
        Me.DelRet.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.DelRet.ForeColor = System.Drawing.SystemColors.ControlText
        Me.DelRet.Location = New System.Drawing.Point(395, 118)
        Me.DelRet.Name = "DelRet"
        Me.DelRet.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.DelRet.Size = New System.Drawing.Size(140, 27)
        Me.DelRet.TabIndex = 3
        Me.DelRet.Text = "߂l(&R)"
        '
        'TextRet
        '
        Me.TextRet.AcceptsReturn = True
        Me.TextRet.AutoSize = False
        Me.TextRet.BackColor = System.Drawing.SystemColors.Window
        Me.TextRet.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.TextRet.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.TextRet.ForeColor = System.Drawing.SystemColors.WindowText
        Me.TextRet.Location = New System.Drawing.Point(8, 150)
        Me.TextRet.MaxLength = 0
        Me.TextRet.Name = "TextRet"
        Me.TextRet.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.TextRet.Size = New System.Drawing.Size(527, 25)
        Me.TextRet.TabIndex = 4
        Me.TextRet.Text = ""
        '
        'DelSts
        '
        Me.DelSts.BackColor = System.Drawing.SystemColors.Control
        Me.DelSts.Cursor = System.Windows.Forms.Cursors.Default
        Me.DelSts.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.DelSts.ForeColor = System.Drawing.SystemColors.ControlText
        Me.DelSts.Location = New System.Drawing.Point(395, 56)
        Me.DelSts.Name = "DelSts"
        Me.DelSts.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.DelSts.Size = New System.Drawing.Size(140, 27)
        Me.DelSts.TabIndex = 1
        Me.DelSts.Text = "Xe[^X(&E)"
        '
        'Polling
        '
        Me.Polling.BackColor = System.Drawing.SystemColors.Control
        Me.Polling.Cursor = System.Windows.Forms.Cursors.Default
        Me.Polling.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.Polling.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Polling.Location = New System.Drawing.Point(280, 184)
        Me.Polling.Name = "Polling"
        Me.Polling.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Polling.Size = New System.Drawing.Size(121, 35)
        Me.Polling.TabIndex = 7
        Me.Polling.Text = "|[O(&P)"
        '
        'PollSts
        '
        Me.PollSts.AcceptsReturn = True
        Me.PollSts.AutoSize = False
        Me.PollSts.BackColor = System.Drawing.SystemColors.Window
        Me.PollSts.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.PollSts.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.PollSts.ForeColor = System.Drawing.SystemColors.WindowText
        Me.PollSts.Location = New System.Drawing.Point(10, 88)
        Me.PollSts.MaxLength = 0
        Me.PollSts.Name = "PollSts"
        Me.PollSts.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.PollSts.Size = New System.Drawing.Size(525, 25)
        Me.PollSts.TabIndex = 2
        Me.PollSts.Text = ""
        '
        'Frame1
        '
        Me.Frame1.BackColor = System.Drawing.SystemColors.Control
        Me.Frame1.Controls.AddRange(New System.Windows.Forms.Control() {Me.YrAdrBox, Me.MyAddress, Me.Label2, Me.Label1})
        Me.Frame1.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Frame1.Location = New System.Drawing.Point(10, 4)
        Me.Frame1.Name = "Frame1"
        Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Frame1.Size = New System.Drawing.Size(525, 47)
        Me.Frame1.TabIndex = 10
        Me.Frame1.TabStop = False
        Me.Frame1.Text = "ݒ"
        '
        'YrAdrBox
        '
        Me.YrAdrBox.BackColor = System.Drawing.SystemColors.Window
        Me.YrAdrBox.Cursor = System.Windows.Forms.Cursors.Default
        Me.YrAdrBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
        Me.YrAdrBox.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.YrAdrBox.ForeColor = System.Drawing.SystemColors.WindowText
        Me.YrAdrBox.Location = New System.Drawing.Point(464, 16)
        Me.YrAdrBox.Name = "YrAdrBox"
        Me.YrAdrBox.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.YrAdrBox.Size = New System.Drawing.Size(49, 23)
        Me.YrAdrBox.TabIndex = 0
        '
        'MyAddress
        '
        Me.MyAddress.AcceptsReturn = True
        Me.MyAddress.AutoSize = False
        Me.MyAddress.BackColor = System.Drawing.SystemColors.Window
        Me.MyAddress.Cursor = System.Windows.Forms.Cursors.IBeam
        Me.MyAddress.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.MyAddress.ForeColor = System.Drawing.SystemColors.WindowText
        Me.MyAddress.Location = New System.Drawing.Point(120, 16)
        Me.MyAddress.MaxLength = 0
        Me.MyAddress.Multiline = True
        Me.MyAddress.Name = "MyAddress"
        Me.MyAddress.ReadOnly = True
        Me.MyAddress.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.MyAddress.Size = New System.Drawing.Size(35, 26)
        Me.MyAddress.TabIndex = 9
        Me.MyAddress.Text = ""
        Me.MyAddress.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        '
        'Label2
        '
        Me.Label2.BackColor = System.Drawing.SystemColors.Control
        Me.Label2.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label2.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.Label2.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label2.Location = New System.Drawing.Point(224, 20)
        Me.Label2.Name = "Label2"
        Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label2.Size = New System.Drawing.Size(241, 19)
        Me.Label2.TabIndex = 12
        Me.Label2.Text = "|[O鑊@AhX ="
        '
        'Label1
        '
        Me.Label1.BackColor = System.Drawing.SystemColors.Control
        Me.Label1.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label1.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.Label1.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label1.Location = New System.Drawing.Point(20, 20)
        Me.Label1.Name = "Label1"
        Me.Label1.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label1.Size = New System.Drawing.Size(103, 19)
        Me.Label1.TabIndex = 11
        Me.Label1.Text = "}CAhX ="
        '
        'Label4
        '
        Me.Label4.BackColor = System.Drawing.SystemColors.Control
        Me.Label4.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label4.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.Label4.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label4.Location = New System.Drawing.Point(8, 128)
        Me.Label4.Name = "Label4"
        Me.Label4.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label4.Size = New System.Drawing.Size(55, 19)
        Me.Label4.TabIndex = 14
        Me.Label4.Text = "߂l"
        '
        'Label3
        '
        Me.Label3.BackColor = System.Drawing.SystemColors.Control
        Me.Label3.Cursor = System.Windows.Forms.Cursors.Default
        Me.Label3.Font = New System.Drawing.Font("lr oSVbN", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(128, Byte))
        Me.Label3.ForeColor = System.Drawing.SystemColors.ControlText
        Me.Label3.Location = New System.Drawing.Point(12, 70)
        Me.Label3.Name = "Label3"
        Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No
        Me.Label3.Size = New System.Drawing.Size(151, 19)
        Me.Label3.TabIndex = 13
        Me.Label3.Text = "|[OXe[^X"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 12)
        Me.ClientSize = New System.Drawing.Size(545, 227)
        Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Exit_Renamed, Me.Initialize, Me.DelRet, Me.TextRet, Me.DelSts, Me.Polling, Me.PollSts, Me.Frame1, Me.Label4, Me.Label3})
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Location = New System.Drawing.Point(192, 310)
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.Manual
        Me.Text = "|[O"
        Me.Frame1.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub
#End Region 
#Region "AbvO[h EBU[h̃T|[g R[h"
	Private Shared m_vb6FormDefInstance As Form1
	Private Shared m_InitializingDefInstance As Boolean
	Public Shared Property DefInstance() As Form1
		Get
			If m_vb6FormDefInstance Is Nothing OrElse m_vb6FormDefInstance.IsDisposed Then
				m_InitializingDefInstance = True
				m_vb6FormDefInstance = New Form1()
				m_InitializingDefInstance = False
			End If
			DefInstance = m_vb6FormDefInstance
		End Get
		Set
			m_vb6FormDefInstance = Value
		End Set
	End Property
#End Region 
    Dim Mode As Integer                                     '[h̐ݒ
    Dim Pstb(15) As Integer                                 'Xe[^XoCg̔z
    Dim Adrs As Integer                                     'AhX쐬Ɏgp
    Dim ErrText As String                                   'eLXg\p
    Dim Delim As Integer                                    'f~^
    Dim gChCmd As GCHandle                                  'CmdzpGCHandle
    Dim gChPstb As GCHandle                                 'PstbzpGCHandle
    Dim pPstb As IntPtr                                     'PstbzpIntPtr
	
	'///// [ tH[[h ] ///////////////////////////////////////////////////////////////////////
	Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		
        For Adrs = 0 To 30                                  '@AhX̍쐬
            YrAdrBox.Items.Add(CStr(Adrs))
        Next Adrs

        YrAdrBox.Text = CStr(1)                             'ݒ

        'PinnednhCmdɕz
        If gChCmd.IsAllocated = False Then
            gChCmd = GCHandle.Alloc(Cmd, GCHandleType.Pinned)
        End If
        'PinnednhPstbɕz
        If gChPstb.IsAllocated = False Then
            gChPstb = GCHandle.Alloc(Pstb, GCHandleType.Pinned)
        End If
        'PinnednhŃIuWFNg̃AhX擾
        pCmd = gChCmd.AddrOfPinnedObject()
        pPstb = gChPstb.AddrOfPinnedObject()
		
	End Sub
	
	'///// [  ] ///////////////////////////////////////////////////////////////////////////////
	Private Sub Initialize_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Initialize.Click
		
        Ret = GpibInit(ErrText)                             'SubClassɂ܂B
		If (Ret = 1) Then GoTo Err_Renamed
		Ret = GpBoardsts(&HAs, Mode)
		
		MyAddress.Text = CStr(MyAddr)
		
        If YrAdrBox.Items.Count = 31 Then                   '}CAhXXg폜܂B
            YrAdrBox.Items.RemoveAt((MyAddr))
            If MyAddr = YrAddr Then
                YrAdrBox.SelectedIndex = 0
            End If
        End If

        If Mode = 1 Then ErrText = "̋@̓}X^ł͂܂ݒmFĂ"
        GoTo Err_Renamed

Err_Renamed:  'G[oꍇ͕\܂
        TextRet.Text = ErrText
		
	End Sub
	
	'///// [ |[O ] ///////////////////////////////////////////////////////////////////////////
	Private Sub Polling_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Polling.Click
		
        For Cnt = 0 To 15                                   'p[^̏
            Pstb(Cnt) = 0
        Next

        PollSts.Text = ""
        TextRet.Text = "|[OĂ܂DDD"
        TextRet.Refresh()

        Cmd(0) = 1
        Cmd(1) = YrAddr
        Ret = GpPoll(pCmd, pPstb)                           'VA|[̎s
        If CheckRet("GpPoll", Ret, ErrText) = 1 Then
            GoTo Err_Renamed
        ElseIf CheckRet("GpPoll", Ret, ErrText) = 2 Then
            ErrText = "SRQ ͂܂łB"
            GoTo Err_Renamed
        End If
        PollSts.Text = "g[JAhX=[ " & Cmd(Pstb(0)) & " ]Xe[^XoCg= [" & Hex(Pstb(Pstb(0))) & " ] H"
        TextRet.Text = "SRQ mF܂B"
Err_Renamed:
        TextRet.Text = ErrText
		
	End Sub
	
	'///// [ @AhX̕ύX ] ///////////////////////////////////////////////////////////////
    Private Sub yradrbox_SelectedIndexChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles YrAdrBox.SelectedIndexChanged

        YrAddr = CInt(YrAdrBox.Text)

    End Sub

    '///// [ ߂l̏ ] /////////////////////////////////////////////////////////////////////////
    Private Sub DelRet_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles DelRet.Click

        TextRet.Text = ""

    End Sub

    '///// [ |[OXe[^X̏ ] ///////////////////////////////////////////////////////////
    Private Sub DelSts_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles DelSts.Click

        PollSts.Text = ""

    End Sub

    '///// [ I ] /////////////////////////////////////////////////////////////////////////////////
    Private Sub Exit_Renamed_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Exit_Renamed.Click

        Ret = GpibExit()                                    'SubClassɂ܂B
        Me.Close()                                          '̃_CAȌIł

    End Sub

    Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        'GCHandlẻ
        If gChCmd.IsAllocated = True Then
            gChCmd.Free()
        End If
        If gChPstb.IsAllocated = True Then
            gChPstb.Free()
        End If
    End Sub
End Class