VB把结果保存在文本里

来源:百度知道 编辑:UC知道 时间:2024/07/08 11:55:34
Dim a() As String
Dim b As String
Dim i As Long, j As Long
a = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(a)
If Len(a(i)) > 0 Then
b = Left(a(i), 6)
For j = Len(b) - 1 To 1 Step -1
b = Left$(b, j) & " "
If InStr(1, Text1.Text, b) = 0 Then
Text2.Text = Text2.Text & vbCrLf & b
End If
Next
End If
Next
现在我想改成直接读取文本不再textbox显示了,就是点一下command就把结果存在一个wang得文本里

Private Sub Command1_Click()
Dim a() As String
Dim b As String
Dim i As Long, j As Long

Dim fileNO As Integer
Dim strTemp As String
a = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(a)
If Len(a(i)) > 0 Then
b = Left(a(i), 6)
For j = Len(b) - 1 To 1 Step -1
b = Left$(b, j) & " "
If InStr(1, Text1.Text, b) = 0 Then
strTemp = strTemp & vbCrLf & b
End If
Next

End If
Next

fileNO = FreeFile
Open "e:\11.txt" For Output As #fileNO
Print #fileNO, strTemp
Close #fileNO
End Sub

Sub CreateAfile
Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)
a.WriteLine("This is a test.")
a.Close
End Sub
写文件的例子