我举个例子,
CommonDialog1.ShowOpen
fname = CommonDialog1.FileName
If fname <> "" Then
ProgressBar1.Visible = True
Open fname For Input As #1
Do Until EOF(1)
ProgressBar1.Value = p_value
            DoEvents
            p_value = p_value + 1
str = Input(1, 1)
End If
Loop
Close 1
很明显,我是想通过ProgressBar来显示读入文件字符的进度,但是我们选择的文件往往是不同的
这句是说,不同的文件它的字符数目是不同的。等我们知道了该文件的字符数目,程序就已经结束了,所以我说我不知道如何在程序核心部分运行前设置ProgressBar.max??
   

解决方案 »

  1.   

    等我们知道了该文件的字符数目,程序就已经结束了
    呵呵,可以用filelen函数返回该文件的字符数目,一个简单的例子:Private Sub Command1_Click()
        Dim p_value As Long
        Dim mbyte As Byte
        Dim filename As String
        Dim mlen As Long
        p_value = 0
        filename = "c:\mc\link.txt"
        mlen = FileLen(filename)
        ProgressBar1.Max = mlen
        Open filename For Binary As #1
        Do Until EOF(1)
            Get #1, p_value + 1, mbyte
            ProgressBar1.Value = p_value
            DoEvents
            p_value = p_value + 1
        Loop
        Close #1
    End Sub