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

📄 dialog.frm

📁 主要是实现超市管理系统中条形码的串口编程
💻 FRM
字号:
VERSION 5.00
Begin VB.Form Dialog 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "对话框标题"
   ClientHeight    =   3945
   ClientLeft      =   2760
   ClientTop       =   3750
   ClientWidth     =   5805
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3945
   ScaleWidth      =   5805
   ShowInTaskbar   =   0   'False
   Begin VB.Frame Frame1 
      Height          =   3615
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   5535
      Begin VB.CommandButton Command2 
         Caption         =   "取消"
         Height          =   375
         Left            =   4080
         TabIndex        =   12
         Top             =   2760
         Width           =   1095
      End
      Begin VB.CommandButton Command1 
         Caption         =   "确定"
         Height          =   375
         Left            =   2760
         TabIndex        =   11
         Top             =   2760
         Width           =   1095
      End
      Begin VB.ListBox List1 
         BackColor       =   &H80000018&
         Height          =   600
         ItemData        =   "Dialog.frx":0000
         Left            =   960
         List            =   "Dialog.frx":000D
         TabIndex        =   5
         Top             =   480
         Width           =   1095
      End
      Begin VB.ListBox List2 
         BackColor       =   &H80000018&
         Height          =   600
         ItemData        =   "Dialog.frx":0029
         Left            =   960
         List            =   "Dialog.frx":0036
         TabIndex        =   4
         Top             =   1560
         Width           =   1095
      End
      Begin VB.ListBox List3 
         BackColor       =   &H80000018&
         Height          =   600
         ItemData        =   "Dialog.frx":0058
         Left            =   960
         List            =   "Dialog.frx":0065
         TabIndex        =   3
         Top             =   2640
         Width           =   1095
      End
      Begin VB.ListBox List4 
         BackColor       =   &H80000018&
         Height          =   600
         ItemData        =   "Dialog.frx":007D
         Left            =   3600
         List            =   "Dialog.frx":008A
         TabIndex        =   2
         Top             =   480
         Width           =   1095
      End
      Begin VB.ListBox List5 
         BackColor       =   &H80000018&
         Height          =   600
         ItemData        =   "Dialog.frx":00A6
         Left            =   3600
         List            =   "Dialog.frx":00B3
         TabIndex        =   1
         Top             =   1560
         Width           =   1095
      End
      Begin VB.Label Label1 
         Caption         =   "串 口"
         Height          =   375
         Left            =   120
         TabIndex        =   10
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label2 
         Caption         =   "波特率"
         Height          =   375
         Left            =   2760
         TabIndex        =   9
         Top             =   360
         Width           =   615
      End
      Begin VB.Label Label3 
         Caption         =   "校 验"
         Height          =   255
         Left            =   120
         TabIndex        =   8
         Top             =   1440
         Width           =   735
      End
      Begin VB.Label Label4 
         Caption         =   "数据位"
         Height          =   255
         Left            =   2760
         TabIndex        =   7
         Top             =   1320
         Width           =   615
      End
      Begin VB.Label Label5 
         Caption         =   "停止位"
         Height          =   375
         Left            =   120
         TabIndex        =   6
         Top             =   2400
         Width           =   735
      End
   End
End
Attribute VB_Name = "Dialog"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False


Option Explicit




Private Sub Command1_Click()


    If (Form2.MSComm1.PortOpen) Then Form2.MSComm1.PortOpen = False
    Form2.MSComm1.CommPort = portid '设置并返回通讯端口号
    Form2.MSComm1.InputLen = 0
    Form2.MSComm1.InBufferSize = 1024
    Form2.MSComm1.OutBufferSize = 1024
    Form2.MSComm1.SThreshold = 1
    Form2.MSComm1.RThreshold = 1
    Form2.MSComm1.settings = baud & "," & parity & "," & databit & "," & stopbit
    '以字符串的形式设置并返回波特率、奇偶校验、数据位、停止位
    Form2.MSComm1.PortOpen = True
    '设置并返回通讯端口的状态。也可以打开和关闭端口
    Unload Me


End Sub

Private Sub Command2_Click()

If (Form2.MSComm1.PortOpen) Then Form2.MSComm1.PortOpen = False
    End

End Sub

Private Sub Form_Load()

List1.ListIndex = 0
List2.ListIndex = 0
List3.ListIndex = 0
List4.ListIndex = 2
List5.ListIndex = 2
End Sub


Private Sub List1_Click()
Select Case List1.ListIndex
    Case 0
        portid = 1
    Case 1
        portid = 2
    Case 2
        portid = 3
    End Select
    
End Sub
Private Sub List2_Click()
 
    Select Case List2.ListIndex
    Case 0
        parity = "n"
    Case 1
        parity = "n"
    Case 2
        parity = "n"
    End Select
End Sub

Private Sub List3_Click()
    Select Case List3.ListIndex
    Case 0
        stopbit = 1
    Case 1
        stopbit = 1.5
    Case 2
        stopbit = 2
    End Select
End Sub

Private Sub List4_Click()
 Select Case List4.ListIndex
    Case 0
        baud = 2400
    Case 1
        baud = 4800
    Case 2
        baud = 9600
   
    End Select
End Sub

Private Sub List5_Click()
Select Case List5.ListIndex
    Case 0
        databit = 6
    Case 1
        databit = 7
    Case 2
        databit = 8
    End Select
End Sub

⌨️ 快捷键说明

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