请问怎样把几个TextBox里的内容写进一个*.txt文件里面??

kgdlnyq 2003-08-26 12:55:52
还有要加一点导出格式的控制
如果导出到word文件又怎样呢??
...全文
60 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xingnup 2003-08-26
  • 打赏
  • 举报
回复
const intLen as integer=10 '假设你要写入的固定长度
str1 as string *intlen
str2 as string *intlen
str3 as string *intlen

open "d:\temp.txt" for output as #1
str1=text1.text
str2=text2.text
str3=text3.text

print #1,str1 '这里可以用Format函数设置你需要的格式
print #1,str2
print #1,str3
......
close #1
射天狼 2003-08-26
  • 打赏
  • 举报
回复
1.
Dim ss As String

ss = Text1.Text & Text2.Text & Text3.Text

Open "C:\a.txt" For Output As #1
Print #1, ss
Close #1



2.
点击菜单 "工程/引用/Microsoft Word 9.0 Object Library"

Dim wd As New Word.Application

wd.Documents.Add
wd.Selection.TypeText Text:=ss '文件内容
wd.ActiveDocument.SaveAs FileName:="c:\dd.doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
planetike 2003-08-26
  • 打赏
  • 举报
回复
贴点代码作参考:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\a.txt", ForAppending, True)
f.writeline "嗨,你好!"
'or f.write "嗨,你好!"
f.Close

Dim MyChar
Open App.Path & "\a.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
MyChar = Input(1, #1) ' 读入一个字符。
Debug.Print MyChar ' 显示到立即窗口。
Loop
Close #1 ' 关闭文件。

Dim TextLine
Open App.Path & "\a.txt" For Input As #1 ' 打开文件。
Do While Not EOF(1) ' 循环至文件尾。
Line Input #1, TextLine ' 读入一行数据并将其赋予某变量。
Debug.Print TextLine ' 在立即窗口中显示数据。
Loop
Close #1 ' 关闭文件。
lihonggen0 2003-08-26
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim TempFile As Long
Dim SaveBytes() As Byte

SaveBytes = StrConv(Text1.Text & Text2.Text & Text3.Text, vbFromUnicode)

TempFile = FreeFile
Open "f:\new.txt" For Binary As #TempFile
Put #TempFile, , SaveBytes
Close TempFile

End Sub
dreamreality 2003-08-26
  • 打赏
  • 举报
回复
Dim OFSO As New Scripting.FileSystemObject
Dim Txt As TextStream
Set Txt = OFSO.OpenTextFile("c:\txt.txt", ForWriting)
Txt.Write text1.Text
Txt.Close

如果要倒入到WORD里面有一点麻烦
mili111 2003-08-26
  • 打赏
  • 举报
回复
open "d:\temp.txt" for output as #1
print #1,text1.text
print #1,text2.text
print #1,text3.text
'依次类推.........
close #1
rainstormmaster 2003-08-26
  • 打赏
  • 举报
回复
假如有3个textbox,可以这样:

Open "d:\mc\mytemp2.txt" For Binary As #1
Put #1, , Text1.Text
Put #1, , Text2.Text
Put #1, , Text3.Text
Close #1

也可以这样:

Dim s As String
s = Text1.Text & Text2.Text & Text3.Text
Open "d:\mc\mytemp.txt" For Binary As #1
Put #1, , s
Close #1

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧