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

📄 mainform.frm

📁 这个是vb编写的控制服务器的程序
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form Form1 
   Caption         =   "控制服务器的模拟"
   ClientHeight    =   3885
   ClientLeft      =   2295
   ClientTop       =   1665
   ClientWidth     =   6450
   LinkTopic       =   "Form1"
   ScaleHeight     =   3885
   ScaleWidth      =   6450
   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          =   924
      Left            =   3720
      Picture         =   "Mainform.frx":0000
      Style           =   1  'Graphical
      TabIndex        =   3
      Top             =   2640
      Width           =   1545
   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          =   924
      Left            =   1200
      Picture         =   "Mainform.frx":0442
      Style           =   1  'Graphical
      TabIndex        =   2
      Top             =   2670
      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          =   1920
      Left            =   810
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   0
      Text            =   "Mainform.frx":0884
      Top             =   540
      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            =   2160
      TabIndex        =   1
      Top             =   150
      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%
  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
          Comm1.Output = "执行" & Right(Buf, Len(Buf) - (StrPos + 1)) & "命令成功…"
          '我们自己的控制子程序
        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 + -