📄 sendfile.frm
字号:
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.Form Form2
BorderStyle = 4 'Fixed ToolWindow
ClientHeight = 1320
ClientLeft = 45
ClientTop = 270
ClientWidth = 3135
LinkTopic = "Form2"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 1320
ScaleWidth = 3135
ShowInTaskbar = 0 'False
StartUpPosition = 1 '所有者中心
Begin MSWinsockLib.Winsock ddd
Left = 2565
Top = 810
_ExtentX = 741
_ExtentY = 741
_Version = 393216
End
Begin VB.Label pb
Appearance = 0 'Flat
AutoSize = -1 'True
BackColor = &H80000005&
Caption = ":"
ForeColor = &H80000008&
Height = 180
Left = -15
TabIndex = 0
Top = -60
Width = 90
End
End
Attribute VB_Name = "Form2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim Freef As Integer
Dim Currentfile As Double
Dim comp As Boolean
Private Sub ddd_Close()
ddd.Close
End Sub
Private Sub ddd_Connect()
On Error Resume Next
Freef = FreeFile '接收端产生该事件
Open "c:\NC_temp" For Binary As Freef
If Form1.PS = "F" Then
Me.Caption = "已连接,我已开始传送文件......"
ddd.SendData "okok" '开始发送的标志
Exit Sub
End If
If Form1.PS = "J" Then
Me.Caption = "已连接,我已开始接收文件"
ddd.SendData "begi"
Else
Me.Caption = "未知连接"
End If
End Sub
Private Sub ddd_DataArrival(ByVal bytesTotal As Long)
Dim Fmsg As String
Dim buff As String
ddd.GetData Fmsg
If Form1.PS = "J" Then '在接收端
If Left(Fmsg, 4) = "begi" Then
buff = Mid(Fmsg, 5)
Put Freef, , buff
ddd.SendData "okok"
If Len(pb.Caption) > 59 Then pb.Caption = ":"
pb.Caption = pb.Caption & ":"
Exit Sub
End If
If Left(Fmsg, 4) = "endf" Then Close: ddd.Close: Unload Form2: MsgBox "OK,已接收完了" & Chr(13) & Chr(10) & "保存在C:\nc_temp", vbInformation + vbSystemModal
End If
If Form1.PS = "F" Then '在发送端
If Left(Fmsg, 4) = "begi" Then
Freef = FreeFile
Open Form1.Selefile For Binary As Freef
Dim File As Single
File = LOF(1)
If File > 199 Then buff = Space(200) Else buff = Space(2)
Currentfile = Len(buff)
If File - Currentfile < 200 Then buff = Space(2)
Get Freef, , buff
ddd.SendData "begi" & buff
pb.Caption = pb.Caption & ":"
If CLng(Currentfile) > CLng(LOF(1)) Then ddd.SendData "endf"
End If
If Left(Fmsg, 4) = "okok" Then
If LOF(1) - Currentfile < 200 Then buff = Space(2) Else buff = Space(200)
Get Freef, , buff
Currentfile = Currentfile + Len(buff)
If Currentfile + 1 > LOF(1) Then
ddd.SendData "endf"
comp = True
Exit Sub
End If
ddd.SendData "begi" & buff
If Len(pb.Caption) > 59 Then pb.Caption = ":"
pb.Caption = pb.Caption & ":"
End If
End If
End Sub
Private Sub ddd_SendComplete()
If comp = True Then
ddd.Close
Unload Me
MsgBox "OK,已传送完了", vbInformation + vbSystemModal
End If
End Sub
Private Sub Form_Load()
ddd.LocalPort = 0
Currentfile = 0
comp = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
ddd.Close
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -