VB中如何设置保存一个文本框中的多行文字?

我做了一个软件,他可以将文本框内的输入的文字保存在C盘里,并成为ha.txt
但是保存的文字只有一行,当我再点击command键进行保存文本内的文字时,将替换原有的一行,请问编写什么代码,可以保存多行文字,谢谢 ,说详细点,我不太懂

第1个回答  2011-03-08
不太明白LZ你的程序目的,到底是只能保存一行成问题啊还是需要它只保存一行?要是想获取文本框的某行文字就需要使用API函数 SendMessage

SendMessage函数例子参考:

'以下在Form需一个TextBox,并设定MultiLine = True, 一个Command Button
Private Sub Command1_Click()
Dim str5 As String
str5 = GetaLine(Text1,1) '取得第二行的字串,以0为基底
End Sub

'以下在.Bas
Option Explicit
Const EM_GETLINE = &HC4
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Public Function GetaLine(Text1 As TextBox, ByVal ntx As Long) As String
Dim str5(255) As Byte '如果您的字串 > 255 byte请自行增加该Byte Array
Dim str6 As String, i As Long

str5(0) = 255 '字串的前两个Byte存该字串的最大长度
str5(0) = 255
i = SendMessage(Text1.hwnd, EM_GETLINE, ntx, str5(0))
If i = 0 Then
GetaLine = ""
Else
str6 = StrConv(str5, vbUnicode)
GetaLine = Left(str6, InStr(1, str6, Chr(0)) - 1)
End If
End Function
第2个回答  2011-03-08
最好能贴出你的源码看一下。
是不是你在读取的时候把text原有的内容覆盖了。要不你你改成
Text1.Text=Text1.Text & “你的内容”
这样试一下
第3个回答  2011-03-08
Dim fs, f, ts
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(App.Path & "\lan.txt") = False Then
fs.CreateTextFile App.Path & "\ha.txt"
End If
Set f = fs.GetFile(App.Path & "\ha.txt")
Set ts = f.OpenasTextStream(2, 0)
ts.write Text1.Text
ts.Close
别忘了给分哦
第4个回答  2011-03-08
Private Sub Command1_Click()
‘以追加的方式打开文件
Open "c:\ha.txt" For Append As #1
Print #1, Text1.Text
Close #1
End Sub本回答被提问者采纳