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

📄 frmcycfile.frm

📁 此程序为标准的TCPIP网络编程
💻 FRM
字号:
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "Comdlg32.ocx"
Begin VB.Form frmCycFile 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "循环发送文件"
   ClientHeight    =   2655
   ClientLeft      =   6765
   ClientTop       =   2955
   ClientWidth     =   4095
   Icon            =   "frmCycFile.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   2655
   ScaleWidth      =   4095
   ShowInTaskbar   =   0   'False
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   100
      Left            =   3600
      Top             =   2160
   End
   Begin MSComDlg.CommonDialog CommonDialog1 
      Left            =   0
      Top             =   2040
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin VB.CommandButton CmdCancel 
      Caption         =   "退出"
      Height          =   375
      Left            =   2400
      TabIndex        =   11
      Top             =   2040
      Width           =   975
   End
   Begin VB.CommandButton CmdStartFile 
      Caption         =   "开始发送"
      Height          =   375
      Left            =   720
      TabIndex        =   10
      Top             =   2040
      Width           =   975
   End
   Begin VB.Frame Frame1 
      Caption         =   "参数设置"
      Height          =   1815
      Left            =   120
      TabIndex        =   0
      Top             =   120
      Width           =   3855
      Begin MSComctlLib.ProgressBar ProgressBar1 
         Height          =   255
         Left            =   2280
         TabIndex        =   12
         Top             =   480
         Width           =   1455
         _ExtentX        =   2566
         _ExtentY        =   450
         _Version        =   393216
         BorderStyle     =   1
         Appearance      =   0
         Enabled         =   0   'False
         Scrolling       =   1
      End
      Begin VB.TextBox TxtFilePath 
         BackColor       =   &H8000000F&
         Height          =   285
         Left            =   960
         TabIndex        =   9
         Text            =   "请选择文件路径"
         Top             =   1305
         Width           =   2415
      End
      Begin VB.CommandButton CmdBrowse 
         Caption         =   "..."
         Height          =   255
         Left            =   3480
         TabIndex        =   8
         Top             =   1320
         Width           =   255
      End
      Begin VB.TextBox TxtCount 
         Alignment       =   2  'Center
         Height          =   285
         Left            =   960
         TabIndex        =   4
         Text            =   "5"
         Top             =   825
         Width           =   735
      End
      Begin VB.TextBox TxtInterval 
         Alignment       =   2  'Center
         Height          =   285
         Left            =   960
         TabIndex        =   3
         Text            =   "1000"
         Top             =   345
         Width           =   735
      End
      Begin VB.Label LblStatus 
         Alignment       =   2  'Center
         Caption         =   "准备发送"
         Height          =   255
         Left            =   2280
         TabIndex        =   13
         Top             =   840
         Width           =   1455
      End
      Begin VB.Label Label5 
         Caption         =   "文件路径"
         Height          =   255
         Left            =   120
         TabIndex        =   7
         Top             =   1320
         Width           =   855
      End
      Begin VB.Label Label4 
         Caption         =   "次"
         Height          =   255
         Left            =   1920
         TabIndex        =   6
         Top             =   840
         Width           =   255
      End
      Begin VB.Label Label3 
         Caption         =   "毫秒"
         Height          =   255
         Left            =   1800
         TabIndex        =   5
         Top             =   360
         Width           =   375
      End
      Begin VB.Label Label2 
         Caption         =   "发送次数"
         Height          =   255
         Left            =   120
         TabIndex        =   2
         Top             =   840
         Width           =   735
      End
      Begin VB.Label Label1 
         Caption         =   "时间间隔"
         Height          =   255
         Left            =   120
         TabIndex        =   1
         Top             =   360
         Width           =   855
      End
   End
End
Attribute VB_Name = "frmCycFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim sCount As Long '剩下还要发送的次数
Dim sendByte() As Byte '文件二进制流

Private Sub CmdBrowse_Click()

'调出打开文件对话框
' Set CancelError is True
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' Set flags
CommonDialog1.Flags = cdlOFNHideReadOnly
' Set filters
CommonDialog1.Filter = "All Files (*.*)|*.*|Text Files " & "(*.txt)|*.txt|"
' Specify default filter
CommonDialog1.FilterIndex = 2
' Display the Open dialog box
CommonDialog1.ShowOpen
' Display name of selected file
TxtFilePath.Text = CommonDialog1.FileName
'MsgBox CommonDialog1.FileName

Exit Sub
  
ErrHandler:
    'User pressed the Cancel button
    Exit Sub
End Sub

Private Sub CmdCancel_Click()
Unload Me
End Sub

Private Sub CmdStartFile_Click()
Dim tInterval As Integer '时间间隔
Dim sTotalCount As Long '要发送的总次数

tInterval = TxtInterval.Text
sTotalCount = TxtCount.Text

Timer1.Enabled = True
Timer1.Interval = tInterval

sCount = sTotalCount

ProgressBar1.Max = sTotalCount
ProgressBar1.Value = 0

CmdStartFile.Enabled = False

'打开文件,并存入二进制流中
Dim fLen As Long '文件的长度
Dim fName As String '文件名(包括路径)
fName = CommonDialog1.FileName
If fName = "" Then
    MsgBox "请选择文件路径!"
    Timer1.Enabled = False
    sCount = 0
    CmdStartFile.Enabled = True
    Exit Sub
End If
fLen = FileLen(fName)
        
ReDim sendByte(fLen - 1) '重新定义二进制流的长度
Open fName For Binary As #1
Get #1, , sendByte
Close #1
End Sub

Private Sub Form_Load()
    Me.Left = frmMain.Left + frmMain.Width - Me.Width
    Me.Top = frmMain.Top
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If Timer1.Enabled Then
    MsgBox "当前正在传送数据,这将导致数据传输中止。"
End If
End Sub

Private Sub Timer1_Timer()
If sCount > 0 Then
    If frmMain.Winsock1.State = 7 Or (Winsock1.Protocol = sckUDPProtocol And udpEnabled) Then
        
        '发送二进制流
        frmMain.Winsock1.sendData sendByte
        sendLen = sendLen + fLen
        frmMain.StatusBar1.Panels(3).Text = "发送:" & sendLen
            
        sCount = sCount - 1
        '显示状态
        LblStatus.Caption = (ProgressBar1.Value + 1) & "/" & ProgressBar1.Max
        '控制进度条
        ProgressBar1.Value = ProgressBar1.Max - sCount
    Else
        MsgBox "网络没有连接,因此不能操作!请检查网络是否通畅。"
        Timer1.Enabled = False
    End If
    
    '处理发送完成后的事情
    If sCount <= 0 Then
        Timer1.Enabled = False
        sCount = 0
        LblStatus.Caption = "发送完毕!"
        CmdStartFile.Enabled = True
    End If
End If
End Sub

⌨️ 快捷键说明

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