常用的文件操作函数
Private Sub Form_Click()
Dim mypath
mypath = CurDir
Print mypath
mypath = CurDir("C")
Print mypath
Dim strtime
strtime = FileDateTime("D:\百川教育")
Print strtime
Dim strlen
strlen = FileLen("D:\百川教育\百川考试软件\zip.dll")
Print strlen
End Sub
打开文件
Open "D:\百川教育\百川考试软件\zip.dll" For Input As #1
Do While Not EOF(1)
Line Input #1, inputstr
Debug.Print inputstr
Loop
Close #1
获取打开文件的大小
Dim filelength
Open "D:\百川教育\百川考试软件\zip.dll" For Input As #1
filelength = LOF(1)
Close #1
顺序文件的读取操作
Private Sub Command1_Click()
Text1.Text = ""
With CommonDialog1
.Initdir = App.Path
.Filter = "文本文件|*.txt"
.showopen
End With
Open CommonDialog1.FileName For Input As #1
Dim str As String
Do While Not EOF(1)
Input #1, str
Text1.Text = Text1.Text & vbNewLine & str
Loop
Close #1
End Sub
Private Sub Command2_Click()
Unload Me
End Sub
Line input#语句
Private Sub Command1_Click()
CommonDialog1.InitDir = App.Path
CommonDialog1.Filter = "文本文件|*.txt"
CommonDialog1.ShowOpen
Text1.Text = CommonDialog1.FileName
End Sub
Private Sub Command2_Click()
Dim myline
If Text2.Text <> "" Then
Text2.Text = ""
Open Text1.Text For Input As #1
Do While Not EOF(1)
Line Input #1, myline
Text2.Text = Text2.Text + myline + vbCrLf
Loop
Close #1
End If
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
这篇博客详细记录了VB编程中常见的文件操作,包括打开文件、获取文件大小以及使用Line Input#语句进行顺序文件的读取操作。
2792

被折叠的 条评论
为什么被折叠?



