扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
Option Explicit Event DownloadProgress(CurBytes As Long, MaxBytes As Long, SaveFile As String) Event DownloadError(SaveFile As String) Event DownloadComplete(MaxBytes As Long, SaveFile As String) 'Public downStat As Boolean Public Function CancelAsyncRead() As Boolean On Error Resume Next UserControl.CancelAsyncRead End Function 'Private Sub Timer1_Timer() ' If Not downStat Then ' Timer1.Enabled = False ' Exit Sub ' End If ' Static Cs As Integer ' If Cs > 2 Then Cs = 0 ' UserControl.Picture = P1(Cs).Picture ' Cs = Cs + 1 ' DoEvents 'End Sub Private Sub UserControl_AsyncReadComplete(AsyncProp As AsyncProperty) On Error Resume Next Dim f() As Byte, fn As Long If AsyncProp.BytesMax <> 0 Then fn = FreeFile f = AsyncProp.Value Open AsyncProp.PropertyName For Binary Access Write As #fn Put #fn, , f Close #fn Else RaiseEvent DownloadError(AsyncProp.PropertyName) End If RaiseEvent DownloadComplete(CLng(AsyncProp.BytesMax), AsyncProp.PropertyName) downStat = False End Sub Private Sub UserControl_AsyncReadProgress(AsyncProp As AsyncProperty) On Error Resume Next If AsyncProp.BytesMax <> 0 Then RaiseEvent DownloadProgress(CLng(AsyncProp.BytesRead), CLng(AsyncProp.BytesMax),AsyncProp.PropertyName) downStat = True: Timer1.Enabled = True End If End Sub 'Private Sub UserControl_Resize() ' SizeIt 'End Sub Public Sub BeginDownload(url As String, SaveFile As String) On Error GoTo ErrorBeginDownload downStat = True UserControl.AsyncRead url, vbAsyncTypeByteArray, SaveFile, vbAsyncReadForceUpdate Timer1.Enabled = True Exit Sub ErrorBeginDownload: downStat = False MsgBox Err & "开始下载数据失败!" _ & vbCrLf & vbCrLf & "错误:" & Err.Description, vbCritical, "错误" End Sub 'Public Sub SizeIt() ' On Error GoTo ErrorSizeIt ' With UserControl ' .Width = ScaleX(32, vbPixels, vbTwips) ' .Height = ScaleY(32, vbPixels, vbTwips) ' End With ' Exit Sub 'ErrorSizeIt: 'End Sub 'Public Sub kill() ' downStat = False ' Dim m As AsyncProperty ' MsgBox m.Value 'End Sub ----------------------------------------------------- |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者