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

📄 form1.frm

📁 Mscomm文件发送
💻 FRM
字号:
VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Begin VB.Form Form1 
   Caption         =   "Form1"
   ClientHeight    =   2220
   ClientLeft      =   60
   ClientTop       =   345
   ClientWidth     =   4035
   LinkTopic       =   "Form1"
   ScaleHeight     =   2220
   ScaleWidth      =   4035
   StartUpPosition =   3  'Windows Default
   Begin VB.CommandButton Command1 
      Caption         =   "SendFile"
      Height          =   495
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   975
   End
   Begin MSComDlg.CommonDialog Cdlg 
      Left            =   720
      Top             =   720
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
      DialogTitle     =   "Send file"
      Filter          =   "*.txt"
      InitDir         =   "C:\"
   End
   Begin MSCommLib.MSComm MSComm1 
      Left            =   120
      Top             =   720
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
      DTREnable       =   -1  'True
   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()
Cdlg.DialogTitle = "Send file..."
Cdlg.Filter = "Textfile (*.TXT)|*.txt|All Files (*.*)|*.*"
Cdlg.InitDir = App.Path
Cdlg.FileName = ""
Cdlg.ShowOpen

' The Function Call
If Cdlg.FileName <> "" Then SendFile (Cdlg.FileName)

End Sub

Private Sub Form_Load()

' Opens the selected com port
MSComm1.CommPort = 2
MSComm1.PortOpen = True

End Sub


' here is the function
Function SendFile(tmp$)

Dim temp$
Dim hsend, bsize, LF&

' Open file
Open tmp$ For Binary Access Read As #2
' Check size on Mscomm1 OutBuffer
bsize = MSComm1.OutBufferSize
' Check file length
LF& = LOF(2)

' This code makes tiny pieces of data (Buffer sized)
' And send's it

Do Until EOF(2)
    
    If LF& - Loc(2) <= bsize Then
        bsize = LF& - Loc(2) + 1
    End If

    ' Make room for some data
    temp$ = Space$(bsize)
    
    ' Put the data piece in the Temp$ string
    Get #2, , temp$

    MSComm1.Output = temp$

    Do
        ret = DoEvents()
    ' Wait until the buffer is empty
    Loop Until MSComm1.OutBufferCount = 0
Loop

' close file
Close #2

End Function

⌨️ 快捷键说明

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