假如你的窗体上的TEXTBOX是控件数组(共6个) Dim fname As String, I As Integer Private Sub Command1_Click() fname = "d:\1.txt" Open fname For Output As 1 For I = 0 To 5 Print #1, Text1(I) Next ResetEnd SubPrivate Sub Command2_Click() fname = "d:\1.txt" Open fname For Input As #1 I = 0 Do While Not EOF(1) Line Input #1, s Text1(I) = s I = I + 1 Loop Reset End Sub这个方法可以使用,当然如果不是控件数组的话,你就得一个一个地将那些数据读出来或写进去。
Function TextStreamTest Const ForReading = 1, ForWriting = 2, ForAppending = 8 Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0 Dim fso, f, ts Set fso = CreateObject("Scripting.FileSystemObject") fso.CreateTextFile "test1.txt" ' Create a file. Set f = fso.GetFile("test1.txt") Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault) ts.Write "Hello World" ts.Close Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault) TextStreamTest = ts.ReadLine ts.Close End Function
Dim fname As String, I As Integer Private Sub Command1_Click() fname = "d:\1.txt " Open fname For Output As 1 For I = 0 To 5 Print #1, Text1(I) Next Reset
End Sub 运行提示TEXT1为错误的参数号为无效的属性值
Dim fname As String, I As Integer Private Sub Command1_Click() fname = "d:\1.txt " Open fname For Output As 1 For I = 0 To 5 Print #1, Text1(I) Next Reset
Dim fname As String, I As Integer
Private Sub Command1_Click()
fname = "d:\1.txt"
Open fname For Output As 1
For I = 0 To 5
Print #1, Text1(I)
Next
ResetEnd SubPrivate Sub Command2_Click()
fname = "d:\1.txt"
Open fname For Input As #1
I = 0
Do While Not EOF(1)
Line Input #1, s
Text1(I) = s
I = I + 1
Loop
Reset
End Sub这个方法可以使用,当然如果不是控件数组的话,你就得一个一个地将那些数据读出来或写进去。
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fso, f, ts
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile "test1.txt" ' Create a file.
Set f = fso.GetFile("test1.txt")
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
ts.Write "Hello World"
ts.Close
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
TextStreamTest = ts.ReadLine
ts.Close
End Function
Private Sub Command1_Click()
fname = "d:\1.txt "
Open fname For Output As 1
For I = 0 To 5
Print #1, Text1(I)
Next
Reset
End Sub
运行提示TEXT1为错误的参数号为无效的属性值
Private Sub Command1_Click()
fname = "d:\1.txt "
Open fname For Output As 1
For I = 0 To 5
Print #1, Text1(I)
Next
Reset
End Sub
运行提示TEXT1为错误的参数号为无效的属性值
==================================
szjhxu(天野) 的代码没有大问题。你运行不正确可能是你的Textbox不是数组控件
最简单的方法就是先添加一个Textbox,然后复制粘贴这个控件,会有相应的对话框,你点是就可以了