使用inet控制元件上傳連接服務器時,如果輸入ip地址錯誤,程式會死住,添加了錯誤處理后(Private Sub ConnectFtp_Click()注釋部分),重新輸入正確的ip地址時程式還是會死,求大神指點!!!謝謝!
Private Sub ConnectFtp_Click()
On Error GoTo err_ret
Inet1.Protocol = icFTP
Inet1.URL = "ftp://" & TextFtp.Text
Inet1.RemotePort = TextPort.Text
Inet1.UserName = TextUser.Text
Inet1.Password = TextPW.Text
Inet1.Execute , "Dir"
Do While frmMain.Inet1.StillExecuting
DoEvents
Loop
ConnectFtp.Caption = "已連接"
ConnectFtp.Refresh
Exit Sub
err_ret:
'MsgBox "請檢查FTP輸入設定"
'Exit Sub
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
'ConnectFtp.Caption = State
'ConnectFtp.Refresh
Dim get_data As String
Dim temp As String
Select Case State
Case icNone '0無狀態可報告
Case icResolvingHost '1該控制元件正在查詢所指定的主機的IP地址
temp = "正在查找..."
MsgBox "正在查找..."
Case icHostResolved '2該控制元件已找到指定主機的IP地址
temp = "已找到IP地址"
MsgBox "已找到IP地址"
Case icConnecting '3該控制元件正在與主機連接
temp = "正在與主機連接..."
MsgBox "正在與主機連接..."
Case icConnected '4該控制元件已與主機連接成功
temp = "連接成功"
MsgBox "連接成功"
Case icRequesting '5該控制元件正在向主機發送請求
temp = "正在發送請求..."
MsgBox "正在發送請求..."
Case icRequestSent '6該控制元件發送請求已成功
temp = "發送請求成功"
MsgBox "發送請求成功"
Case icReceivingResponse '7該控制元件正在接收主機的回應
temp = "正在接收主機的回應"
MsgBox "正在接收主機的回應"
Case icResponseReceived '8該控制元件已成功接收主機的回應
temp = "已接收主機的回應"
MsgBox "已接收主機的回應"
Case icDisconnecting '9該控制元件正在解除與主機的連接
temp = "正在解除與主機的連接..."
MsgBox "正在解除與主機的連接..."
Case icDisconnected '10該控制元件已解除與主機的連接
temp = "已解除與主機的連接"
MsgBox "已解除與主機的連接"
Case icError '11與主機通訊時出現錯誤
' temp = Inet1.ResponseCode & Inet1.ResponseInfo
temp = "請檢查網路連接和輸入設定"
MsgBox "請檢查網路連接和輸入設定"
Case icResponseCompleted '12該請求已經完成,并且所有資料已經接收到
temp = "已接收到資料"
MsgBox "已接收到資料"
End Select
End Sub
uj5u.com熱心網友回復:
僅供參考:Dim ExeStr As String
Dim Done As Boolean
Private Sub cmd(cmdstr As String)
Do
If Inet1.StillExecuting = False Then Exit Do
Loop
ExeStr = cmdstr
Done = False
Debug.Print ExeStr; "="
Inet1.Execute , ExeStr
Do
DoEvents
If Done Then Exit Do
Loop
End Sub
Public Sub ReadNewWav(wav As String)
Inet1.URL = "ftp://xxx.xxx.xxx.xxx"
Inet1.UserName = "username"
Inet1.Password = "password"
cmd "GET " + wav + ".WAV " + App.Path + "\" + wav + ".WAV"
cmd "QUIT"
End Sub
Private Sub Command1_Click()
Command1.Enabled = False
ReadNewWav ("00000021")
Command1.Enabled = True
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim intFile As Integer
Dim vtData() As Byte
Dim str As String
'On Error GoTo ISCerr
Debug.Print "State="; State,
Select Case State
Case 0
Debug.Print "icNone"
Case 1
Debug.Print "icHostResolvingHost"
Case 2
Debug.Print "icHostResolved"
Case 3
Debug.Print "icConnecting"
Case 4
Debug.Print "icConnected"
Case 5
Debug.Print "icRequesting"
Case 6
Debug.Print "icRequestSent"
Case 7
Debug.Print "icReceivingResponse"
Case 8
Debug.Print "icResponseReceived"
If Left(ExeStr, 2) = "CD" Then Done = True
Case 9
Debug.Print "icDisconnecting"
Case 10
Debug.Print "icDisconnected"
Done = True
Case 11
Debug.Print "icError of [" + ExeStr + "]="; Inet1.ResponseInfo
Done = True
Case 12
Debug.Print "icResponseCompleted----------------"
Do
str = Inet1.GetChunk(1024, icString)
If LenB(str) = 0 Then Exit Do
Debug.Print str
Loop
Done = True
End Select
Exit Sub
ISCerr:
Resume Next
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/88089.html
標籤:網絡編程
