如题

解决方案 »

  1.   


    Private Sub Form_Load()
    ManipFiles
    End Sub
    Public Sub ManipFiles()
      Dim fso, f1, f2, f3
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set f1 = fso.CreateTextFile("c:\testfile.txt", True)
      MsgBox "Writing file."
      ' Write a line.
      f1.Write ("This is a test.")
      ' Close the file to writing.
      f1.Close
      MsgBox "Create a tmp directory."
      fso.CreateFolder ("C:\tmp")
        MsgBox "Moving file to c:\tmp."
      ' Get a handle to the file in root of C:\.
      Set f2 = fso.GetFile("c:\testfile.txt")
      ' Move the file to \tmp directory.
      f2.Move ("c:\tmp\testfile.txt")
      MsgBox "Create a temp directory."
      fso.CreateFolder ("C:\temp")
      MsgBox "Copying file to c:\temp."
      ' Copy the file to \temp.
      f2.Copy ("c:\temp\testfile.txt")
      MsgBox "Deleting files."
      ' Get handles to files' current location.
      Set f2 = fso.GetFile("c:\tmp\testfile.txt")
      Set f3 = fso.GetFile("c:\temp\testfile.txt")
      ' Delete the files.
      f2.Delete
      f3.Delete
      MsgBox "Deleting folders."
      ' Delete the folders.
      fso.DeleteFolder ("C:\tmp")
      fso.DeleteFolder ("C:\temp")
      MsgBox "All done!"
    End Sub
      

  2.   

    用2进制比较灵活open 文件地址 for output(输出)/input(输入) as #1
        line input (逐步行输入) #1 输入内容
        print (输出)
    close #1
    大概就是这样,可以找资料看!
      

  3.   

    读文件:
    dim inp as string
    open "文件路径如c:\ff.txt" for input as #1
    input #1,inp
    close#1
    写文件:
    open "文件路径" for append as #1   '''append是每次在文件末尾写入,不删除其它已经存在的文件.如果换成output则删除其它文件后再写入
    print#1,text1.text   '''如果print换成write则写进txt中后自动加双引号
    close#1
      

  4.   

    或者调用 FileSystemObject 也可以
      

  5.   

    Open "C:\www\sdfsdf.txt" For Output As #1
     Print #1, "1.", "sdf"
     Print #1, "2.", "sdf"
     Print #1, "3.", "sdf"
    Close #1
      

  6.   

    开心一下
    http://dzh.mop.com/topic/readSub.jsp?sid=5775660
      

  7.   

    我只好跟楼主说说如何用VB读txt文件吧!
        Dim Fsote As New FileSystemObject, Tste As TextStream
        Dim i As Integer
        Dim txtRows As Integer, txtContent As String
        '定义文本文件的行数,再逐行读出来,适用于文件行数较少的txt文件
        txtRows = 10
       
        Set Tste = Fsote.OpenTextFile(App.Path + "\***.txt", 1)
        For i = 1 To txtRows
            txtContent = Trim(Tste.ReadLine)
        Next i
      

  8.   

    再说说如何写txt文件;
         Dim Fsote As New FileSystemObject, Tste As TextStream
         Set Tste = Fsote.CreateTextFile(App.Path + "\**.txt", True)
         Tste.WriteLine "************"
         Tste.Close
      

  9.   

    1.用 FILESYSTEMOBJECT 对象。
    2.用 OPEN 方法。
      

  10.   

    好象没人说FileSystemObject的例子,我给楼主一个:
    Dim fso As FileSystemObject, f_fso As TextStream, unFile As String
        unFile = "c:\un.bat"      '要写的文件
        Set fso = New FileSystemObject
        Set f_fso = fso.CreateTextFile(unFile, True)
        f_fso.WriteLine "要写进去的一行的内容"
    '读的话用f_fso.readLing
    '最后要记得关闭
        f_fso.Close
        Set f_fso = Nothing
        Set fso = Nothing
      

  11.   

    大家已经说了fso和open方式,我就只好来点别的了。
    放个richtextbox框,然后用richtextbox1.LoadFile("你要开的文件名")
    然后写就是richtextbox1.SaveFile("你要存的文件名")
      

  12.   

    嗯。又想到个更绝的办法。。
    Shell ("notepad c:\a.bmp")
    哈哈哈哈
      

  13.   

    噢,发错地方了,
    open for binary好啊