读书人

为什么使用inet控件传输数据其State

发布时间: 2012-02-10 21:27:42 作者: rapoo

为什么使用inet控件传输数据,其StateChanged事件始终是icReceivingResponse状态?

VB code
Private Sub Command1_Click()Command1.Enabled = FalseMe.MousePointer = 11If Len(Text1.Text) > 5 ThenText2.Text = Inet1.OpenURL(Text1.Text, icString)ElseMsgBox "输入网址错误"End IfEnd SubPrivate Sub Form_Terminate()If Inet1.StillExecuting ThenInet1.CancelEnd IfEnd SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)Select Case StateCase icConnectingLabel2.Caption = "正在建立连接......"Case icConnectedLabel2.Caption = "建立连接成功"Case icReceivingResponseLabel2.Caption = "正在传输数据......"Case icErrorLabel2.Caption = "传输中发生错误"Case icDisconnectedLabel2.Caption = "数据传输完毕"Me.MousePointer = 0Command1.Enabled = TrueEnd SelectEnd Sub

问题就在于等了很久都没有看到“数据传输完毕”!一直都是“正在传输数据......”。不知道是代码错误还是别的原因。
在下新手。。。。。。(_)

[解决办法]
Inet控件只有在异步传输的时候才能更新其全部状态,你用Inet1.OpenURL是同步传输,也就是说必须等到Inet1.OpenURL执行完后后面的语句才能执行,此时其状态其实没什么意义,OpenURL执行完毕就代表着数据接收完毕或出错;

你用异步传输的Inet1.Execute方法,就可以显示所有的状态了,不过数据的接收得靠你自己写

读书人网 >VB

热点推荐