Creating database records from a Text File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ncag
    New Member
    • Jun 2006
    • 4

    #1

    Creating database records from a Text File

    I have a program that I download a text file that has multiple lines in the following style:

    This is the title.

    Verse 1
    This is the first line
    This is the second line

    Verse 2
    This is the first line
    This is the second line

    I can parse the text file to some degree but what I really need is to be able to read the first line and add a new record and then read the next line and know if the next line is Verse 1 or Verse 2 and then add the next lines to the record. I am not sure how to loop through correctly.

    Thank you for your time and information.


    Sincerely,

    Keith Kelly
  • VBPhilly
    New Member
    • Aug 2007
    • 95

    #2
    Originally posted by ncag
    I have a program that I download a text file that has multiple lines in the following style:

    This is the title.

    Verse 1
    This is the first line
    This is the second line

    Verse 2
    This is the first line
    This is the second line

    I can parse the text file to some degree but what I really need is to be able to read the first line and add a new record and then read the next line and know if the next line is Verse 1 or Verse 2 and then add the next lines to the record. I am not sure how to loop through correctly.

    Thank you for your time and information.


    Sincerely,

    Keith Kelly
    Looks like you have a predictable format such as:

    Verse1
    Line1
    Line2

    You'll need to loop the file, as normal, and simply look for "Verse". This is your record begin flag.
    Then, you use counting to get the rest of the data. Line1, Line2.

    Then, do the same thing until EOF.

    Ide help more if I had a data sample. Show us sample data.

    Comment

    • ncag
      New Member
      • Jun 2006
      • 4

      #3
      Thanks for replying.

      Here is the code that I am using. It is rough. Here is the actual text file lines.

      I have a large text box that I first pasre the text file into to look at. Then I have a command button that actually parses the textbox.

      command button code to parse the text file into the textbox

      Dim nfilenum As Integer
      Dim llinecount As Integer
      Dim snextline As String
      Dim stext As String

      nfilenum = FreeFile
      CommonDialog1.I nitDir = "g:\vb projects\icastt est\songs\"
      CommonDialog1.F ilter = "*.txt"
      CommonDialog1.S howOpen
      gPath = CommonDialog1.F ileName

      Open gPath For Input As nfilenum
      ' Read the contents of the file
      Do While Not EOF(nfilenum)
      Line Input #nfilenum, snextline
      snextline = snextline & vbCrLf
      stext = stext & snextline
      Loop
      Text1.Text = stext
      close nfilenum


      command button code to parse the textbox and create the database records

      Dim pos As Integer
      Dim entry() As String

      entry = Split(Text1.Tex t, vbCrLf & vbCrLf)
      pos = 0

      Do While pos < UBound(entry)
      If Trim$(entry(pos )) <> "" Then
      database.addnew
      database.record set!field = trim$entry(pos) )
      End If
      pos = pos + 1
      Loop



      The problem I can't get over is once I find the "Verse 1" header I do not know how to continue adding to the database until it gets to the next vbcrlf.

      Here is the actual text file:

      Here I Am To Worship


      Verse 1
      Light of the world
      You stepped down into darkness
      Opened my eyes let me see
      Beauty that made
      This heart adore You
      Hope of a life spent with You


      Chorus 1
      So here I am to worship
      Here I am to bow down
      Here I am to say that You're my God
      And You're altogether lovely
      Altogether worthy
      Altogether wonderful to me


      Verse 2
      King of all days
      Oh so highly exalted
      Glorious in heaven above
      Humbly You came
      To the earth You created
      All for love's sake became poor


      Misc 1
      (BRIDGE)
      And I'll never know how much it cost
      To see my sin upon that cross
      And I'll never know how much it cost
      To see my sin upon that cross



      Thank you very much.

      Sincerely,

      Keith Kelly
      Last edited by ncag; Sep 6 '07, 01:30 AM. Reason: Not Finished

      Comment

      Working...