Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Popluate fields from different lines

Status
Not open for further replies.

tnayfeh

Programmer
Apr 21, 2004
39
0
0
CA
I have a text file that is read using the code below. What I need to do is populate one field from a line depending on the value in strValue then loop to the next line and populate the remaining fields in the table.

Code:
  Do While f.AtEndOfStream <> True
    strBuffer = f.readline
        
         astrBufferArray = Split(strBuffer, " ")
         strValue = astrBufferArray(0)

            rs.AddNew
            txtMessage = Split(astrBufferArray(6), Chr(9))
             rs!Type = Left(strValue, 1)
             rs!Date = Mid(astrBufferArray(0), 4, 10)
             rs!Time = Mid(astrBufferArray(0), 15, 5)
                     
             rs.Update
  Loop
 
The way I interpreted your statement. I read a line of text (line 1). I split this line of text, and I check the first field of this line (field 1). Depending on what this field says I add something to a table (not quit sure what that is). Call the record added to the table (record 1). Next I read the next line of text (line 2) and stick some of the remaining fields into record 1. I also get the value of field 1, line 2 in order to repeat the process. This is a guess of what you were saying, it is not real clear.

Code:
'need this to jump start the routine
 If Not F.endofstream Then
    strBuffer = F.ReadLine
    astrBufferArray = Split(strBuffer, " ")
    strValue = astrBufferArray(0)
 End If

 Do While F.AtEndOfStream <> True
   Select Case strValue
   Case "caseOne"
     rs.AddNew
     rs.Fields("your field") = astrBufferArray(1)
     rs.update
     strBuffer = F.ReadLine
     astrBufferArray = Split(strBuffer, " ")
     strValue = astrBufferArray(0)
     rs.Edit
     rs.Fields("your next field") = astrBufferArray(2)
     rs.Fields("anotherfield") = astrBufferArray(3)
     rs.Update
   Case "caseTwo"
     rs.AddNew
     rs.Fields("your field") = astrBufferArray(4)
     rs.update
     strBuffer = F.ReadLine
     astrBufferArray = Split(strBuffer, " ")
     strValue = astrBufferArray(0)
     rs.Edit
     rs.Fields("your next field") = astrBufferArray(2)
     rs.Fields("anotherfield") = astrBufferArray(3)
     rs.Update
    end select
  Loop
End Sub
Obviously depending on what is really going on the actions in the Case statement could be put into one or two functions that return astrBufferArray and strvalue. I just repeated the code. An example would make this clear.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top