How to Make Fields from Text File
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
How to Make Fields from Text File
Hi, I have to make labels for about 65 items. Is there an easy way to read a text file and use each line as a label?
THX
THX
Jeff G potts
-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Re: How to Make Fields from Text File
You can read a text file with tab delimited columns and return delimited rows into a scrolling datagrid.
http://lessons.runrev.com/spaces/lesson ... s/datagrid
MyTextFile.txt - <Tab> and <Return> are actual tab and return keys on the keyboard
Labels<Tab>ColumnHeader2<Tab>ColumnHeader3<Return>
FirstName:<Return>
SurName:<Return>
Email:<Return>
etc.
this should get you started in your research
or you could loop thru theData and create Label fields as you go.
But thats a lot of LiveCode work setting all the properties up
for 65 fields on a single card.
May be too busy visually for the user.
Much tighter on a dataGrid.
hthnh - here to help - not hinder
http://lessons.runrev.com/spaces/lesson ... s/datagrid
MyTextFile.txt - <Tab> and <Return> are actual tab and return keys on the keyboard
Labels<Tab>ColumnHeader2<Tab>ColumnHeader3<Return>
FirstName:<Return>
SurName:<Return>
Email:<Return>
etc.
this should get you started in your research
Code: Select all
...
if there is a file theFolderAndFileName then
put url ("file:" & theFolderAndFileName) into theData
put true into firstLineContainsColumnNames -- or false, depending
set the dgText[firstLineContainsColumnNames] of group datagrid1 of card myCard to empty
set the dgText[firstLineContainsColumnNames] of group datagrid1 of card myCard to theData
-- Answer "File: " & theFolderAndFileName & " - Exists"
else
-- Answer "File: " & theFolderAndFileName & " - Does NOT Exist"
end if
...
But thats a lot of LiveCode work setting all the properties up
for 65 fields on a single card.
May be too busy visually for the user.
Much tighter on a dataGrid.
hthnh - here to help - not hinder
Last edited by BarrySumpter on Tue Aug 30, 2011 10:15 pm, edited 1 time in total.
All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Re: How to Make Fields from Text File
Hi Jeff,
Waht label do you want to set? Of buttons? Just curious
Reading the file:
...
put url("file:" & "you path to file/here.txt") into tAllLabels
...
Now you have the text file in a variable that you can process, but see above, need a bit more info to continue.
Ideally the buttons (or whatever need to be LABELed) are numbered from 1 to X according to the lines in the text file!
Best
Klaus
sure this is possible, but the scripting depends on how your "items" (= LiveCode objects?) are organized!jpottsx1 wrote:Hi, I have to make labels for about 65 items. Is there an easy way to read a text file and use each line as a label?
Waht label do you want to set? Of buttons? Just curious

Reading the file:
...
put url("file:" & "you path to file/here.txt") into tAllLabels
...
Now you have the text file in a variable that you can process, but see above, need a bit more info to continue.
Ideally the buttons (or whatever need to be LABELed) are numbered from 1 to X according to the lines in the text file!
Best
Klaus
Re: How to Make Fields from Text File
Do you mean print actual labels? Klaus and Barry have spoken about an interpretation that you want to create 65 individual label fields, each containing a single line from your text? In either case, the solution is very simple. Write back.
Craig Newman
Craig Newman
Re: How to Make Fields from Text File
I was trying to take a text file with one field delimited with a carriage return at the end of each record.
Example:
Feelings Of Guilt (cr)
Feeling Irritable And Intolerant Of Others (cr)
Lack Of Motivation And Little Interest In Things (cr)
Difficulty Making Decisions (cr)
Lack Of Enjoyment (cr)
I want to read the data, and then create labels (ie text blocks) on a card using one line of data for one label.
Example:
Feelings Of Guilt (cr)
Feeling Irritable And Intolerant Of Others (cr)
Lack Of Motivation And Little Interest In Things (cr)
Difficulty Making Decisions (cr)
Lack Of Enjoyment (cr)
I want to read the data, and then create labels (ie text blocks) on a card using one line of data for one label.
Jeff G potts
Re: How to Make Fields from Text File
Hi Jeff,
But we still don't know what EXACTLY you want to to with the lines
Best
Klaus
OK, reading the file is explained in my earlier post, now you can loop through the variable:jpottsx1 wrote:I want to read the data, and then create labels (ie text blocks) on a card using one line of data for one label.
Code: Select all
...
repeat with i = 1 to the num of lines of tAllLabels
## do something with: line i of tAllLabels
## Example:
put line 1 of tAllLabels into fld ("the label field" && i)
## Will work if you have 65 fields with the name "the label field 1" ..."the label field 65"
end repeat
...

Best
Klaus
Re: How to Make Fields from Text File
I just want to create a text label/Label Field on a card. ie the descriptive name of a field placed upon a card.
Jeff G potts
Re: How to Make Fields from Text File
Hi Jeff,
AHA!
OK, do this:
See also "templatefield" in the dictionary!
Best
Klaus
AHA!

OK, do this:
Code: Select all
...
## We need to make all newly created fields NOT editable!
set the locktext of the templatefield to true
repeat with i = 1 to the num of lines of tAllLabels
put line i of tAllLabels into tLabel
## Create a new field
create field ("Label" && i)
set the text of fld ("Label" && i) to tLabel
## now you ONLy need to take care of positioning your fields ;-)
## set the loc of fld ("Label" && i) to ???
end repeat
...
Best
Klaus