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

📄 frmmain.frm

📁 一个VB实现串口通讯的经典示例.非常简明, 使用, 本人大部分通讯程序与之类同
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Begin VB.Form frmMain 
   Caption         =   "410K Test"
   ClientHeight    =   5115
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   7380
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   ScaleHeight     =   5115
   ScaleWidth      =   7380
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton cmdStop 
      Caption         =   "Stop"
      Height          =   255
      Left            =   6600
      TabIndex        =   9
      Top             =   0
      Width           =   735
   End
   Begin VB.ListBox lstAteCmd 
      Height          =   1620
      Left            =   120
      TabIndex        =   8
      Top             =   3120
      Width           =   7215
   End
   Begin VB.TextBox txtFailureCount 
      Height          =   285
      Left            =   1560
      Locked          =   -1  'True
      TabIndex        =   5
      Text            =   "0"
      Top             =   4800
      Width           =   1575
   End
   Begin VB.CommandButton cmdQuit 
      Caption         =   "&Quit"
      Height          =   255
      Left            =   6600
      TabIndex        =   3
      Top             =   4800
      Width           =   735
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   2640
      Top             =   0
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   End
   Begin VB.ListBox lstMsg 
      Height          =   2400
      Left            =   120
      TabIndex        =   2
      Top             =   360
      Width           =   7215
   End
   Begin VB.CommandButton cmdStart 
      Caption         =   "&Start"
      Height          =   255
      Left            =   5760
      TabIndex        =   1
      Top             =   0
      Width           =   735
   End
   Begin VB.Label Label4 
      AutoSize        =   -1  'True
      Caption         =   "ATE Commands:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   120
      TabIndex        =   7
      Top             =   2880
      Width           =   1395
   End
   Begin VB.Label Label3 
      AutoSize        =   -1  'True
      Caption         =   "ATE Commands:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   435
      Left            =   1500
      TabIndex        =   6
      Top             =   2880
      Width           =   15
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      Caption         =   "Failure counter:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   120
      TabIndex        =   4
      Top             =   4800
      Width           =   1350
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      Caption         =   "Msg:"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   195
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   420
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private m_bStopTestLoop As Boolean

Public Property Get StopTestLoop() As Boolean
    StopTestLoop = m_bStopTestLoop
End Property

Public Property Let StopTestLoop(Value As Boolean)
    m_bStopTestLoop = Value
End Property

Private Sub cmdStart_Click()
    Init
    TestLoop2
    'Me.cmdQuit.Enabled = False
End Sub

Private Sub cmdStop_Click()
    If MsgBox("Confirm to stop ?", vbYesNo + vbDefaultButton2, "Stop") = vbYes Then
        frmMain.DisplayMsg "Manual stop request"
        m_bStopTestLoop = True
        Me.cmdQuit.Enabled = True
        Me.Refresh
    End If
End Sub

Private Sub CmdQuit_Click()
    If Not bAppRunning Then
        Unload Me
    Else
        m_bStopTestLoop = True
        Me.Refresh
        bQuitApp = True
    End If
End Sub

Public Sub DisplayMsg(ByVal sMsg As String, Optional ByVal bLogToFile As Boolean = True)
Dim sLine As String

    sLine = Format(Now, "hh:mm:ss ") & sMsg
    With lstMsg
        .AddItem sLine
        If .ListCount > 500 Then .RemoveItem 0
    End With
    
    If bLogToFile Then oResultLog.WriteLine sLine
End Sub

Private Sub Form_Load()
    With oResultLog
        .OpenLog App.Path & "\410KBs.txt"
        .WriteLine "--- Start on " & Format(Now, "yyyy mmm dd hh:mm:ss")
    End With
    
    frmMain.Caption = frmMain.Caption & " Ver " & App.Major & "." & App.Minor & "." & App.Revision

End Sub

Private Sub Form_Unload(Cancel As Integer)
    oLog.WriteLine Format(Now, "hh:mm:ss ") & " Quit"
End Sub

Public Sub UpCountFailure()
Dim lCount As Long

    lCount = CLng(Me.txtFailureCount.Text)
    lCount = lCount + 1
    Me.txtFailureCount.Text = Format(lCount, "#,###,##0")
    Me.Refresh
    
    oResultLog.WriteLine "Failure count = " & lCount
End Sub

⌨️ 快捷键说明

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