如何讀取及寫入文字檔?

首先準備Command1、Command2、Text1(MutliLine=True)各一個然後輸入:

Private Sub Command1_Click()
'讀檔
Dim F As Integer, Source As String, StrTemp As String
 F = FreeFile
 StrTemp = Text1.Text = ""
 Open "C:\Autoexec.bat" For Input As #F
  Do Until EOF(F)
   Line Input #F, Source
   StrTemp = StrTemp & Source & vbCrLf
  Loop
 Close #F
 Text1.Text = StrTemp
End Sub

Private Sub Command2_Click()
'存檔
Dim F As Integer
 F = FreeFile
 Open "C:\Abc.txt" For Output As #F
  Print #F, Text1.Text
 Close #F
End Sub


上一頁