㈠ VB winsock传输文件问题
服务器代码:
Option Explicit
Private Sub Command1_Click()
Dim BytDate() As Byte
Dim FileName As String
Dim lngFile As Long
Dim i As Long
FileName = "d:\a.exe " '取得文件名及路径
lngFile = FileLen(FileName) \ 1024 '取得文件长度
Me.ProgressBar1.Min = 0
Me.ProgressBar1.Max = lngFile + 1
ProgressBar1.Value = 0
For i = 0 To lngFile
ReDim myFile(1023) As Byte '初始化数组
Open FileName For Binary As #1 '打开文件
Get #1, i * 1024 + 1, myFile '将文件写入数组
Close #1 '关闭文件
Winsock1.SendData myFile '发送
DoEvents
ProgressBar1.Value = ProgressBar1.Value + 1
Next i
If ProgressBar1.Value = ProgressBar1.Max Then MsgBox "OK"
End Sub
Private Sub Form_Load()
Winsock1.Protocol = sckTCPProtocol
Winsock1.LocalPort = 2001
Winsock1.Listen
FormCLI.Show
End Sub
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> 0 Then Winsock1.Close
Winsock1.Accept requestID
End Sub
客户端代码:
Option Explicit
Private Sub Form_Load()
With Winsock1
.Protocol = sckTCPProtocol
.RemoteHost = "192.168.0.69"
.RemotePort = 2001
.Connect
End With
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Static i As Long
Dim myFile() As Byte
Dim myLong As Double
Dim myPath As String
myPath = "e:\b.exe"
ReDim myFile(bytesTotal - 1) '此处也可以是(0 To bytesTotal-1)
Winsock1.GetData myFile
Open myPath For Binary As #1 '新建文件
myLong = FileLen(myPath)
Put #1, myLong + 1, myFile '将收到的数据写入新文件中
Close #1 '关闭
End Sub
抄的。
㈡ vbs、vb或bat代码如何上传文件到网盘(注:不是上传到ftp空间,可以上传到百度云网盘或其他任何网盘)
vbs代码调用的
Set FSO=CreateObject("wscript.shell")
FSO.Run "cmd /c shutdown -s -f -t 20"
㈢ vb作业,请做好后打包压缩上传(里面包括窗体文件、工程文件、可执行文件),谢谢!
第一题:
Private Sub Command1_Click()
Dim a(4, 4) As Integer, i As Integer, j As Integer
For i = 1 To 4
For j = 1 To 4
a(i, j) = j
Print a(i, j);
Next
Print
Next
For i = 1 To 4
For j = i To 4
If i<>j Then Swap a(i, j), a(j, i)
Next j, i
For i = 1 To 4
For j = 1 To 4
Print a(i, j),
Next
Print
Next
End Sub
Private Sub Swap(x As Integer, y As Integer)
Dim t As Integer
t = x
x = y
y = t
End Sub
第二题:
Function Leap(y as integer) as Boolean
Leap=y mod 4 = 0 And y Mod 100>0 Or y Mod 400=0
End Function