請問,只要我重複一直按\"開啟\"、\"存檔\"(檔案內容空白),內容會不斷的換行,不知如何解決?
(表單配置:frmEditor.txtFileName→MultiLine=True.txtEditor.lbTitle.cmdOpen.cmdSave.cmdQuit)
我寫的程式內容如下:
Private Sub cmdOpen_Click()
Dim ReadBuffer As String, FileNo As Integer
txtEditor = \"\"
FileNo = FreeFile
Open txtFileName.Text For Input As #FileNo
While Not EOF(FileNo)
Line Input #FileNo, ReadBuffer
txtEditor.Text = txtEditor.Text + ReadBuffer + vbCrLf
Wend
Close #FileNo
End Sub
Private Sub cmdQuit_Click()
End
End Sub
Private Sub CmdSava_Click()
FileNo = FreeFile
Open txtFileName.Text For Output As #FileNo
Print #FileNo, txtEditor.Text
Close #FileNo
End Sub
2006-01-18 11:44:15 · 2 個解答 · 發問者 天使 4 in 電腦與網際網路 ➔ 程式設計
建議你加個首行旗標。
dim flagFirstLine as boolean
flagFirstLine = True
然後將原程式的這一行
txtEditor.Text = txtEditor.Text + ReadBuffer + vbCrLf
改成:
if flagFirstLine = True then
txtEditor.Text = txtEditor.Text + ReadBuffer
flagFirstLine = false
else
txtEditor.Text = txtEditor.Text + vbCrLf+ ReadBuffer
end if
這個程式片斷很好用,讀出與寫入均用得著,試用看吧!
2006-01-19 09:32:14 · answer #1 · answered by fun 3 · 0⤊ 0⤋
Private Sub cmdOpen_Click()
Dim ReadBuffer As String, FileNo As Integer
txtEditor = ""
FileNo = FreeFile
Open txtFileName.Text For Input As #FileNo
While Not EOF(FileNo)
Line Input #FileNo, ReadBuffer
txtEditor.Text = txtEditor.Text + ReadBuffer + vbCrLf
Wend
Close #FileNo
'加這行把txtEditor最後面的vbCrLf刪去
txtEditor.Text =Left(txtEditor.Text ,Len(txtEditor.Text )-1)
End Sub
2006-01-19 08:57:02 · answer #2 · answered by W.J.S. 7 · 0⤊ 0⤋