formatting text files (glyn here with some questions)

Jacques Hausser Jacques.Hausser at ie-zea.unil.ch
Mon Oct 20 12:43:22 EDT 2003


> I'm creating a touchscreen application and i need help on a few 
> things...
>
> 1)     On one of my screens i have multiple text fields. As it's touch
> screen i have an onscreen keyboard.
> I know i can give each field 'focus' by touching the relevant field. 
> But how
> can i enter text into each field independant of eachother??
>
> 2)     I can write to text files easily but i would like to have a 
> strutured
> output. IE
>
> ITEM A           £9.00
> ITEM AA         £2.30
> ITEM AND HS      .90
>
> how can i get this? as all its comeing out with at the moment is...
>
> ITEM A£9.00
> ITEM AA£2.30
> ITEM HS.90
>
> but there is a catch to this problem. the text is imported from 
> another .TXT
> file per item. which the .TXT file is created on screen. so every item 
> will
> have a different length. unknown until the user puts in the name of the
> item.
>
> 3)     Thanks in advance.
>

Hello Glyn
for 1)
I'm not sure I have understood your question, but look at the focus 
command, it can help.
for 2)
You can use

put "%" & maxlength & "s" into f
put format(f,thestring) after URL(file...)
but you will get right justified strings of length maxlength. Look at 
the transcript dictionnary for details.

To get left justified words or strings of length maxlength, I would use 
something like:

function trailingspaces thestring,maxlength
    put (maxlength - the length of thestring) into n
    if n < 0 then
	-- some error management here, perhaps some truncation of thestring
    end if
    repeat n
       put space after thestring
    end repeat
    return thestring
end trailingspace

and then:

put trailingspaces (theitem,maxitemlength) & 
trailingspaces(theprice,maxpricelength) & return after URL (file:....)

just choose your maxlengths conveniently (that is, at least two chars 
more than the longest item). You can compute it by script.

Hope it helped

Jacques

Prof. J. Hausser
Institute of Ecology - Zoology and Animal Ecology
University of Lausanne
CH-1015 Lausanne-Dorigny
tel: ++ 41 21 692 41 62
fax: ++ 41 21 692 41 65



More information about the use-livecode mailing list