How to read a file and write into a text file?

前端 未结 4 1784
悲哀的现实
悲哀的现实 2020-12-17 21:01

I want to open mis file, copy all the data and write into a text file.

My mis file.

File name – 1.mis

M3;3395;44;0;1;;20090404;094144;8193;3;         


        
4条回答
  •  [愿得一人]
    2020-12-17 21:17

        An example of reading a file:
    Dim sFileText as String
    Dim iFileNo as Integer
    iFileNo = FreeFile
    'open the file for reading
    Open "C:\Test.txt" For Input As #iFileNo
    'change this filename to an existing file! (or run the example below first)
    
    'read the file until we reach the end
    Do While Not EOF(iFileNo)
    Input #iFileNo, sFileText
    'show the text (you will probably want to replace this line as appropriate to your program!)
    MsgBox sFileText
    Loop
    
    'close the file (if you dont do this, you wont be able to open it again!)
    Close #iFileNo
    (note: an alternative to Input # is Line Input # , which reads whole lines).
    
    
    An example of writing a file:
    Dim sFileText as String
    Dim iFileNo as Integer
    iFileNo = FreeFile
    'open the file for writing
    Open "C:\Test.txt" For Output As #iFileNo
    'please note, if this file already exists it will be overwritten!
    
    'write some example text to the file
    Print #iFileNo, "first line of text"
    Print #iFileNo, " second line of text"
    Print #iFileNo, "" 'blank line
    Print #iFileNo, "some more text!"
    
    'close the file (if you dont do this, you wont be able to open it again!)
    Close #iFileNo
    

    From Here

提交回复
热议问题