471,066 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

Convert textbox contents to files

How would I convert the contents of a textbox into text files.

Say I have a textbox containin the following...
13-02-00 - Paul Oakenfold
06-02-00 - William Orbit
30-01-00 - Laurent Garnier
23-01-00 - Guy Ornadel
16-01-00 - Dave Clarke
09-01-00 - Scott Bond
02-01-00 - Mr C
I would like to loop thru the textbox and need each line to be saved as a
text file under that name. So I would end up with 7 blank text files e.g....

13-02-00 - Paul Oakenfold.txt
06-02-00 - William Orbit.txt
30-01-00 - Laurent Garnier.txt
23-01-00 - Guy Ornadel.txt
16-01-00 - Dave Clarke.txt
09-01-00 - Scott Bond.txt
02-01-00 - Mr C.txt

I've tried getting the contents of the textbox

Thanks....

Jul 17 '05 #1
2 3648
Here's one way....

Needs a command button
'=================
Option Explicit

Private Sub Command1_Click()
Const START_PATH = "C:\Temp\"
Dim sFullPath As String
Dim v As Variant
Dim i As Integer
Dim iFile As Integer

'Split the contents into an array
v = Split(Text1.Text, vbCrLf)
iFile = FreeFile

For i = 0 To UBound(v)
If Len(v(i)) > 0 Then
iFile = FreeFile
sFullPath = START_PATH & v(i)
Debug.Print "Creating " & sFullPath & " ...."
Open sFullPath For Output As iFile
Close iFile
End If
Next
Debug.Print "Done"

End Sub

Private Sub Form_Load()
Text1.Text = ""
Text1.SelText = "13-02-00 - Paul Oakenfold.txt" & vbCrLf
Text1.SelText = "06-02-00 - William Orbit.txt" & vbCrLf
Text1.SelText = "30-01-00 - Laurent Garnier.txt" & vbCrLf
Text1.SelText = "23-01-00 - Guy Ornadel.txt" & vbCrLf
Text1.SelText = "16-01-00 - Dave Clarke.txt" & vbCrLf
Text1.SelText = "09-01-00 - Scott Bond.txt" & vbCrLf
Text1.SelText = "02-01-00 - Mr C.txt" & vbCrLf

End Sub
'=================

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep it in the groups..
"Paul" <12**************@btinternet.com> wrote in message
news:bj**********@sparta.btinternet.com...
How would I convert the contents of a textbox into text files.

Say I have a textbox containin the following...
13-02-00 - Paul Oakenfold
06-02-00 - William Orbit
30-01-00 - Laurent Garnier
23-01-00 - Guy Ornadel
16-01-00 - Dave Clarke
09-01-00 - Scott Bond
02-01-00 - Mr C
I would like to loop thru the textbox and need each line to be saved as a
text file under that name. So I would end up with 7 blank text files e.g....

13-02-00 - Paul Oakenfold.txt
06-02-00 - William Orbit.txt
30-01-00 - Laurent Garnier.txt
23-01-00 - Guy Ornadel.txt
16-01-00 - Dave Clarke.txt
09-01-00 - Scott Bond.txt
02-01-00 - Mr C.txt

I've tried getting the contents of the textbox

Thanks....


Jul 17 '05 #2
Thanks Ken, works a treat.

"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:#S**************@TK2MSFTNGP09.phx.gbl...
Here's one way....

Needs a command button
'=================
Option Explicit

Private Sub Command1_Click()
Const START_PATH = "C:\Temp\"
Dim sFullPath As String
Dim v As Variant
Dim i As Integer
Dim iFile As Integer

'Split the contents into an array
v = Split(Text1.Text, vbCrLf)
iFile = FreeFile

For i = 0 To UBound(v)
If Len(v(i)) > 0 Then
iFile = FreeFile
sFullPath = START_PATH & v(i)
Debug.Print "Creating " & sFullPath & " ...."
Open sFullPath For Output As iFile
Close iFile
End If
Next
Debug.Print "Done"

End Sub

Private Sub Form_Load()
Text1.Text = ""
Text1.SelText = "13-02-00 - Paul Oakenfold.txt" & vbCrLf
Text1.SelText = "06-02-00 - William Orbit.txt" & vbCrLf
Text1.SelText = "30-01-00 - Laurent Garnier.txt" & vbCrLf
Text1.SelText = "23-01-00 - Guy Ornadel.txt" & vbCrLf
Text1.SelText = "16-01-00 - Dave Clarke.txt" & vbCrLf
Text1.SelText = "09-01-00 - Scott Bond.txt" & vbCrLf
Text1.SelText = "02-01-00 - Mr C.txt" & vbCrLf

End Sub
'=================

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep it in the groups..
"Paul" <12**************@btinternet.com> wrote in message
news:bj**********@sparta.btinternet.com...
How would I convert the contents of a textbox into text files.

Say I have a textbox containin the following...
13-02-00 - Paul Oakenfold
06-02-00 - William Orbit
30-01-00 - Laurent Garnier
23-01-00 - Guy Ornadel
16-01-00 - Dave Clarke
09-01-00 - Scott Bond
02-01-00 - Mr C
I would like to loop thru the textbox and need each line to be saved as a text file under that name. So I would end up with 7 blank text files e.g....
13-02-00 - Paul Oakenfold.txt
06-02-00 - William Orbit.txt
30-01-00 - Laurent Garnier.txt
23-01-00 - Guy Ornadel.txt
16-01-00 - Dave Clarke.txt
09-01-00 - Scott Bond.txt
02-01-00 - Mr C.txt

I've tried getting the contents of the textbox

Thanks....



Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Ketta | last post: by
5 posts views Thread by manmit.walia | last post: by
4 posts views Thread by Davor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.