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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating variables where data = variable name 1

Status
Not open for further replies.

PatMcLaughlin

Programmer
Dec 10, 2010
97
US
I am attempting to get data from a text file where I receive data to populate a crystal report. It comes to me in a form like this:

Name : John Doe
Address : 123 Here
Phone : 123-456-7890
(80 more follow)

If for instance the 'Phone' has no data, it will not appear in the text file.
I have created a cursor with all of the possible variables, defined all possible variables (i.e. LOCAL lcName, lcAddress, lcPhone) and I have a routine that will read the text file line by line. Using the colon:)) I have parsed out the information to capture "Name" and "John Doe". I cannot find a way to make lcName = "John Doe"
 
try strextract()

Ali Koumaiha
TeknoSoft Inc.
Michigan
 
I suggest instead of creating a list of variables, just create an object and use ADDPROPERTY() to add the properties you find in the text file:

Code:
Local loRecord, lcLine, lcProperty, lcValue, laLines[1]

ALINES(laLines,FILETOSTR("thefile.txt"))
loRecord = CreateObject("Empty")
For Each lcLine In 
   lcProperty = Alltrim(STREXTRACT(lcLine,"",":"))
   lcValue = Alltrim(STREXTRACT(lcLine,":",""))
   Addproperty(loRecord,lcProperty,lcValue)
EndFor

Now the loRecord.Name is "Jon Doe", loRecord.Address is "123 Here" and you can Gather NAME loRecord into a record of your prepared cursor, if it's fields match the property names.

Bye, Olaf.
 
Olaf... As always you are the man! I am close. I have never tried to "Gather" and do not really know what it is. I did try to run the line

APPEND FROM ARRAY laLines

This put data into the Cursor but not the correct data. Can you bounce me one more time.
 
Trying to make the job hard again... A simple
GATHER NAME loRecord
gave me the cursor.
 
You already found it,

you can also INSERT INTO alias NAME loRecord to create a new record with that data.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top