VB 常用代码

    技术2022-05-19  21

    1. 打开文件对话框

    工程-->部件-->Microsoft Common Dialog Control 6.0 

    ImportDialog.InitDir = App.Path '默认打开目录

    ImportDialog.Filter = "文本文件(*.txt)|*.txt|数据文件(*.dat)|*.dat" '文件过滤器

    ImportDialog.ShowOpen '打开对话框

    If Not Len(ImportDialog.FileName) = 0 Then

    Open ImportDialog.FileName For Input As #1

        Do Until EOF(1)

             Line Input #1, newURL 

       Loop

    Close #1

    End If

    2.回车换行符 vbCrLf 是VB回车换行符 chr(10) & chr(13) 用 vbCrLf 会空出一行,用chr(13)就正好 3. 数组长度 用ubound()函数知道数组的上限,lbound()函数知道数组的下限,ubound()-lbound()+1就是数组元素的个数 例如: dim a(10) as long dim nLen as long nLen = ubound(a) - lbound(a) + 1 '这里上限是10,下限是0,结果是11 4. WebBrowser控件下载进度条 进度条ProgressBar控件:工程-部件-MicroSoft Windows Common Controls 6.0 Private Sub WebBrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long) If ProgressMax = 0 Then Exit Sub ProgressBar1.Max = ProgressMax If Progress <> -1 And Progress <= ProgressMax Then ProgressBar1.Value = Progress End If End Sub

    最新回复(0)