VB程序学习代码记录20160731

这篇博客详细记录了VB编程中常见的文件操作,包括打开文件、获取文件大小以及使用Line Input#语句进行顺序文件的读取操作。

常用的文件操作函数

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值