VB 常用代码

前端之家收集整理的这篇文章主要介绍了VB 常用代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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










原文链接:https://www.f2er.com/vb/261389.html

猜你在找的VB相关文章