Read a text file
davis.phil at comcast.net
Mon Jan 17 19:11:03 EST 2005
I'll throw my hat in the ring too.
Things this script assumes:
- there are 3 data values per line
- every value is quoted
- no value has any embedded double-quotes
- value #1 (name) may or may not contain an embedded comma
- labels are in a group whose 'backgroundBehavior' property = true
on mouseUp -- script of a button
-- get the file
answer file "Extract info from which file?"
if it = empty then exit mouseUp
put url ("file:" & it) into tFile
-- change all most probable variations of the value separator
-- to a non-keyboard char
put numToChar(222) into tDlm
replace (quote & comma & quote) with tDlm in tFile
replace (quote & space & comma & quote) with tDlm in tFile
replace (quote & space & comma & space & quote) with tDlm in tFile
replace (quote & comma & space & quote) with tDlm in tFile
-- remove all remaining quotes
replace quote with "" in tFile
-- process each line in the file
set the itemDelimiter to tDlm -- same char as used above
repeat for each line tLine in tFileText
put item 1 of tLine into fld "label1"
put item 2 of tLine into fld "label2"
put item 3 of tLine into fld "label3"
create card -- for next line of values
delete last card -- last card was never loaded with values
-- now each line is displayed on a separate card
Paul Salyers wrote:
> How do I read a text file then insert the information in a label?
> Text file format will be:
> "Name","ID","Email at Address.net"
> There will be 3 labels "Name", "ID", and "Email address"
> Paul Salyers
> PS1 - Senior Rep.
> PS1 at softseven.org
> use-revolution mailing list
> use-revolution at lists.runrev.com
More information about the Use-livecode