您的位置:程序门 -> vb -> 网络编程



inet下载网络进度条的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


inet下载网络进度条的问题
发表于:2007-02-25 18:34:39 楼主
我用inet下载的进度条有时候会停止响应,比如网络断的时候一直显示“请等待..”

我想设定一个超时时间,在一定时间没响应就显示:超时更新失败!

代码如下请高手指点!
private   sub   inet1_statechanged(byval   state   as   integer)
            dim   binbuffer()           as   byte
            dim   sngprogerssvalue           as   single
            dim   iblock           as   long
       
                    on   error   resume   next
                            iblock   =   0
       
                            select   case   state
       
                                    case   icresponsecompleted
                                            command2.enabled   =   false
                                            '打开文件供写入
                                            open   app.path   &   "\ "   &   filename   for   binary   access   write   as   #1
       
                                            do       '从缓冲区读取数据
                                                            doevents
       
                                                            binbuffer   =   inet1.getchunk(512,   icbytearray)
                                                            'strtext       =       strtext       &       strbuffer
                                                            iblock   =   iblock   +   1
                                                            if   m_lngdocsize   >   0   then
                                                                            '获得进度百分比值
                                                                            sngprogerssvalue   =   int((iblock   *   512   /   m_lngdocsize)   *   100)
                                                                            '更新进度标签显示内容
                                                                            lblprogressinfo.caption   =   "已下载       "   &   cstr(iblock   *   512)   &   "       字节       ( "   &   cstr(sngprogerssvalue)   &   "%) "
                                                                            '用新值更新进度条控件
                                                                            progressbar1.value   =   sngprogerssvalue
                                                                            '写入文件
                                                                            put   #1,   ,   binbuffer()
                                                            end   if
       
                                            loop   until   iblock   *   512   > =   m_lngdocsize
                                            '关闭文件
                                            close   #1
                                            'msgbox   "图片更新完成 ",   vbokonly   or   vbinformation,   "在线更新 "
                                            lblprogressinfo.caption   =   "更新完成! "
                                            re   =   systemparametersinfo(spi_setdeskwallpaper,   0,   "beijin.bmp ",   0)
                                            command2.enabled   =   true
                                          '   end
                                    case   icresponsereceived
       
                                            if   m_lngdocsize   =   0   then
       
                                                            '读取页面文件大小
                                                            if   len(inet1.getheader( "content-length "))   >   0   then
                                                                            m_lngdocsize   =   clng(inet1.getheader( "content-length "))
                                                                            if   (m_lngdocsize   =   0)   then
                                                                                        '       msgbox       "读取远程数据出错 ",       vbokonly       or       vbexclamation,       "在线升级 "
                                                                                            lblprogressinfo.caption   =   " "
                                                                                            call   start
                                                                            end   if
       
                                                                    else       'not       len(inet1.getheader( "content-length "))...
                                                                            'msgbox       "error! ",       vbokonly       or       vbexclamation,       "在线升级 "
                                                                            lblprogressinfo.caption   =   " "
                                                                            call   start
                                                            end   if
       
                                            end   if
       
                                    case   icerror
                                            'msgbox       "与主机通信出错 ",       vbokonly       or       vbexclamation,       "在线升级 "
                                            lblprogressinfo.caption   =   " "
                                                call   start
                                    case   icresolvinghost
                                            lblprogressinfo.caption   =   "正在查找主机... "
       
                                    case   ichostresolved
                                            lblprogressinfo.caption   =   "已经找到主机 "
       
                                    case   icconnecting
                                            lblprogressinfo.caption   =   "正在联系主机 "
       
                                    case   icconnected
                                            lblprogressinfo.caption   =   "已经连接到主机 "
       
                                    case   icrequesting
                                            lblprogressinfo.caption   =   "正在发送请求... "
       
                                    case   icrequestsent
                                            lblprogressinfo.caption   =   "成功发送请求 "
       
                                    case   icreceivingresponse
                                            lblprogressinfo.caption   =   "正在接收回应... "
       
                    case   icdisconnecting
                                    lblprogressinfo.caption   =   "正在断开连接... "
       
                    case   icdisconnected
                                    lblprogressinfo.caption   =   "已经断开连接 "
       
    end   select
    '   end
    end   sub
    sub   start()
    '文件大小值复位
       
                    m_lngdocsize   =   0
       
                    '复位进度条控件
                    progressbar1.value   =   0.001
       
                    '显示进度的标签内容设为空
                    lblprogressinfo.caption   =   " "
       
                    '定义itc控件使用的协议为http协议
                    inet1.protocol   =   ichttp
       
                    '调用EXECute方法向web服务器发送http请求
                    inet1.EXECute   trim$(strurl),   "get "
                    lblprogressinfo.caption   =   "请等待... "
          're   =   systemparametersinfo(spi_setdeskwallpaper,   0,   "e:\serverpic\beijin.bmp ",   0)
    end   sub


快速检索

最新资讯
热门点击