Convert textbox contents to files

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul

    #1

    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....





  • Ken Halter

    #2
    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.Tex t, 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" <1231878SPAMHAT ER@btinternet.c om> wrote in message
    news:bjqvoh$7ig $1@sparta.btint ernet.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]


    Comment

    • Paul

      #3
      Re: Convert textbox contents to files

      Thanks Ken, works a treat.



      "Ken Halter" <Ken_Halter@Use _Sparingly_Hotm ail.com> wrote in message
      news:#SCVKwLeDH A.2140@TK2MSFTN GP09.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.Tex t, 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" <1231878SPAMHAT ER@btinternet.c om> wrote in message
      > news:bjqvoh$7ig $1@sparta.btint ernet.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]


      Comment

      Working...