Dim WithEvents a As CommandButton
Private Sub Form_Load()
Set a = Controls.Add("VB.CommandButton", "a1")
a.Left = 200
a.Top = 100
a.Width = 1000
a.Height = 400
a.Visible = True
End Sub
Dim WithEvents a As MSComm
Private Sub a_OnComm()
Select Case a.CommEvent
Case comEvReceive
a.InputLen = 0 '読み取るバイト数を指定 0は全て読み込む
Label1.Caption = a.Input
End Select
End Sub
Private Sub Command1_Click()
a.OutBufferCount = 0 'バッファクリア
Do
a.Output = "送信文字列" & vbCr & vbLf
Loop While a.OutBufferCount >= 1
End Sub
Private Sub Form_Load()
Set a = CreateObject("MSCommLib.MSComm")
a.CommPort = 11
a.Settings = "9600,N,8,1"
a.PortOpen = True
a.RThreshold = 1
End Sub