Connecting Tech Pros Worldwide Forums | Help | Site Map

Convert textbox contents to files

Paul
Guest
 
Posts: n/a
#1: Jul 17 '05
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....






Ken Halter
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Convert textbox contents to files


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" <1231878SPAMHATER@btinternet.com> wrote in message
news:bjqvoh$7ig$1@sparta.btinternet.com...[color=blue]
> 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....
>
>
>
>
>[/color]


Paul
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Convert textbox contents to files


Thanks Ken, works a treat.



"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> wrote in message
news:#SCVKwLeDHA.2140@TK2MSFTNGP09.phx.gbl...[color=blue]
> 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" <1231878SPAMHATER@btinternet.com> wrote in message
> news:bjqvoh$7ig$1@sparta.btinternet.com...[color=green]
> > 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[/color][/color]
a[color=blue][color=green]
> > text file under that name. So I would end up with 7 blank text files[/color][/color]
e.g....[color=blue][color=green]
> >
> > 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....
> >
> >
> >
> >
> >[/color]
>
>[/color]


Closed Thread


Similar Visual Basic 4 / 5 / 6 bytes