📄 table_test.frm
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 3465
ClientLeft = 2715
ClientTop = 1980
ClientWidth = 5025
LinkTopic = "Form1"
ScaleHeight = 3465
ScaleWidth = 5025
Begin VB.Timer Timer2
Interval = 3000
Left = 3000
Top = 240
End
Begin VB.TextBox Text2
Height = 495
Left = 1800
TabIndex = 5
Top = 1800
Width = 2895
End
Begin VB.CommandButton Command2
Caption = "接收"
Height = 495
Left = 2280
TabIndex = 4
Top = 2640
Width = 1215
End
Begin VB.TextBox Text1
Height = 495
Left = 1800
TabIndex = 3
Top = 1200
Width = 2895
End
Begin VB.Timer Timer1
Left = 4200
Top = 240
End
Begin VB.CommandButton Command1
Caption = "发送"
Height = 495
Left = 600
TabIndex = 0
Top = 2640
Width = 1215
End
Begin MSCommLib.MSComm MSComm1
Left = 3960
Top = 2520
_ExtentX = 1005
_ExtentY = 1005
_Version = 327680
DTREnable = -1 'True
EOFEnable = -1 'True
End
Begin VB.Label Label2
Caption = "发送数据"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Left = 240
TabIndex = 2
Top = 1920
Width = 1215
End
Begin VB.Label Label1
Caption = "返回数据"
BeginProperty Font
Name = "宋体"
Size = 12
Charset = 134
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 240
TabIndex = 1
Top = 1200
Width = 1215
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
Dim x1, x2, sline As String
Dim nfilehandle As Integer
Const filename = "send.txt"
nfilehandle = FreeFile
Open filename For Input As #nfilehandle
Do While Not EOF(nfilehandle) ' 循环至文件尾。
Input #nfilehandle, sline
x2 = x2 + sline + Chr(26)
Loop
Close #nfilehandle ' 关闭文件。
x1 = sends((x2))
Text2.Text = x1
End Sub
Private Sub Command2_Click()
Dim x As String
x = receive()
Text1.Text = x
End Sub
Private Sub Form_Load()
Form1.MSComm1.CommPort = 1
' 9600 波特,无奇偶校验,8 位数据,一个停止位。
Form1.MSComm1.Settings = "9600,N,8,1"
Form1.MSComm1.EOFEnable = True '只有先设其为真comEvEOF才能触发oncomm事件
' Form1.MSComm1.RThreshold = 1 '当输入字符小于此值时 comEvReceive才能触发oncomm事件
Form1.Timer2.Enabled = True
Form1.Timer2.Interval = 3000
End Sub
Private Sub Timer1_Timer()
Form1.Timer1.Enabled = False
End Sub
Private Sub Timer2_Timer()
Dim x As String
x = receive()
Text1.Text = x
End Sub
Private Sub MSComm1_OnComm()
Select Case MSComm1.CommEvent
' Handle each event or error by placing
' code below each case statement
' 错误
Case comEventBreak ' 收到 Break。
Case comEventCDTO ' CD (RLSD) 超时。
Case comEventCTSTO ' CTS Timeout。
Case comEventDSRTO ' DSR Timeout。
Case comEventFrame ' Framing Error
Case comEventOverrun '数据丢失。
Case comEventRxOver '接收缓冲区溢出。
Case comEventRxParity ' Parity 错误。
Case comEventTxFull '传输缓冲区已满。
Case comEventDCB '获取 DCB] 时意外错误
' 事件
Case comEvCD ' CD 线状态变化。
Case comEvCTS ' CTS 线状态变化。
Case comEvDSR ' DSR 线状态变化。
Case comEvRing ' Ring Indicator 变化。
Case comEvReceive ' 收到 RThreshold # of chars.
x = receive()
Text1.Text = x
Case comEvSend ' 传输缓冲区有 Sthreshold 个字符 '
Case comEvEOF ' 输入数据流中发现 EOF 字符
x = receive()
Text1.Text = x
End Select
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -