⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainform.frm

📁 这个是一个有关数据服务器的vb小程序
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Caption         =   "数据服务器模拟"
   ClientHeight    =   3660
   ClientLeft      =   1215
   ClientTop       =   585
   ClientWidth     =   6375
   LinkTopic       =   "Form1"
   ScaleHeight     =   3660
   ScaleWidth      =   6375
   Begin VB.CommandButton Command1 
      Caption         =   "清除接收区"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   876
      Left            =   3960
      Picture         =   "Mainform.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   2280
      Width           =   1425
   End
   Begin MSCommLib.MSComm Comm1 
      Left            =   270
      Top             =   180
      _ExtentX        =   794
      _ExtentY        =   794
      _Version        =   393216
      DTREnable       =   -1  'True
      RThreshold      =   1
   End
   Begin VB.CommandButton CmdExit 
      Cancel          =   -1  'True
      Caption         =   "结束系统"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   876
      Left            =   1140
      Picture         =   "Mainform.frx":0442
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   2310
      Width           =   1395
   End
   Begin VB.TextBox txtReceive 
      BeginProperty Font 
         Name            =   "Times New Roman"
         Size            =   12
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   1644
      Left            =   900
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   0
      Text            =   "Mainform.frx":0884
      Top             =   480
      Width           =   4716
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "**命令接收区**"
      BeginProperty Font 
         Name            =   "宋体"
         Size            =   12
         Charset         =   134
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   240
      Index           =   0
      Left            =   2280
      TabIndex        =   1
      Top             =   90
      Width           =   1680
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
''''''''''''''''''''''''''''''''''''''
'使用命令按钮控件
'结束系统
'若未执行关闭通信端口的动作,则
'系统结束时,同时也关闭串行通信端口
''''''''''''''''''''''''''''''''''''''
Private Sub CmdExit_Click()
  End
End Sub

''''''''''''''''''''''''''''''''''''''
'MSComm的OnComm事件程序
'由CommEvent属性值的不同,将各别的程序代码写入
'相关的子程序中。
'在此例中,只要RThresold中的设置字符数到达时
'便会使得CommEvent属性值变成comEvReceive
'因此接收的子程序便被执行;并进行相关运算
''''''''''''''''''''''''''''''''''''''
Private Sub Comm1_OnComm()
  Dim t&, Buf$, StrPos%, CmdStr$
  Dim i%
  Select Case Comm1.CommEvent
    ' 借着取代底下每一个 case 语句来处理每个事件与错误
 ' 事件
    Case comEvCD    ' CD 线的状态发生变化.
    Case comEvCTS   ' CTS 线的状态发生变化.
    Case comEvDSR   ' DSR 线的状态发生变化.
    Case comEvRing  ' Ring Indicator 变化.
    Case comEvReceive   ' 收到 RThreshold # of Data
      t = GetTickCount()
      Do
        DoEvents
      Loop Until GetTickCount - t > 100
      Buf = Trim(Comm1.Input)  '从输入缓冲区读取数据
      If Len(Buf) < 2 Then Exit Sub
      txtReceive.Text = txtReceive.Text + Buf
      StrPos = InStr(1, Buf, "%%")
      If StrPos < 1 Then
        Comm1.Output = "未收到正常命令!"
      Else
        CmdStr = Right(Buf, Len(Buf) - (StrPos + 1))
        'Comm1.Output = "执行" & CmdStr & "命令中…"
        '我们自己的子程序
        If UCase(Trim(CmdStr)) <> "DATA" Then
          Comm1.Output = "命令不正确!"
          Exit Sub
        End If
        txtReceive.Text = txtReceive.Text + "数据发送中…"
        For i = 0 To 20
          Comm1.Output = Trim(Str(GetData())) & ","
        Next i
        Comm1.Output = "!"
       txtReceive.Text = txtReceive.Text + "发送完成。"
      End If
    Case comEvSend  ' 传输缓冲区有 Sthreshold 个字符                            '
    End Select

End Sub

''''''''''''''''''''''''''''''''''''''
'使用命令按钮控件
'清空显示区的内容
''''''''''''''''''''''''''''''''''''''
Private Sub Command1_Click()
  txtReceive.Text = ""
End Sub

''''''''''''''''''''''''''''''''''''''
'窗体的加载事件
'打开通信端口
'相关的通信参数也可以在还未打开之前
'先行指定,然后再打开通信端口
''''''''''''''''''''''''''''''''''''''
Private Sub Form_Load()
  Comm1.PortOpen = True
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -