Page 1 of 2

the text I want

Posted: Sat May 31, 2014 5:03 am
by robm80
This is the line in my database.
ANBO,John Foo,meij,http://anbo.discount4u.nl,Lidnr: 2205111 Landelijk: Pb 18003 3501 CA Utrecht tel: 030 2330060 email:info@anbo.nl http://www.anbo.nl

The text shown =
sshot-5.jpg
BUT
I want this text shown as:
sshot-6.jpg
I tried to do it with CR, but nope.
any help?
Rob

Re: the text I want

Posted: Sat May 31, 2014 5:48 am
by Simon
Hi Rob,
As I shouldn't be answering these questions outright I'll give you a hint:

put "Lidnr:,Landelijk:,tel:,email:" into myVar
repeat with x = 1 to the number of items in myVar
and wordOffset

With those I was able to get the output you wanted.

Need more help?
Just ask.

Simon
Edit; oops I see I left out http:// in myVar

Re: the text I want

Posted: Sat May 31, 2014 10:12 am
by robm80
Yes Simon, I need more help.
I don't know what to do with the wordoffset.
Where item 5 of each databaseline always is the text for field "note"
My readout script might be:
get selectedtext of fld "index"
get lineoffset(it, fld "index")
get line it of field "DB1" of cd "DB"
put item 5 of it into myVar
wordoffset
repeat with i = 1 wordoffset
put item i of myVar &cr after tVar
end repeat
put tVar into fld "note"

I played with wordoffset but never got a good answer:
f.i. put wordoffset("Lidnr: 2205111", "Landelijk: Pb 18003 3501 CA Utrecht tel: 030 2330060", "email: info@anbo.nl www.anbo.nl")

What is the right syntax, to be used for every item 5

thanks
Rob

Re: the text I want

Posted: Sat May 31, 2014 11:26 am
by Klaus
Hi Rob,

is this really the content of ONE field in your database:
ANBO,John Foo,meij,http://anbo.discount4u.nl,Lidnr: 2205111 Landelijk: Pb 18003 3501 CA Utrecht tel: 030 2330060 email:info@anbo.nl http://www.anbo.nl
?
Or do you have separate fields for "Lidnr." etc?
If not, how do you retrieve the data in Livecode?
And is the LABEL (Lidnr., Landelijk etc.) really part of the retrieved data?


Best

Klaus

Re: the text I want

Posted: Sat May 31, 2014 12:02 pm
by Simon
Tip #2
I see you know how to use lineOffset, wordOffset is used in a similar way. Please see the Dictionary entry.

Klaus asked a good question, but I know some people who call a spreadsheet a database.

Simon
Edit: Oh I see you call the field Note, which means that its free text and Lindr, email, tel etc. Might not be in it? My method won't work then.

Re: the text I want

Posted: Sat May 31, 2014 12:06 pm
by robm80
Klaus, Probably my idea about a database is different from yours.
My database ia a card containing289 lines, that have to be readout with the scipt I sent, but where I get lost withthe WORDOFFSET.

Here you see i part of my "database":
4allclients,robmeyer@hetnet.nl,11220076,https://www.4allclients.com, 4AllClients.com? B.V. Opaalstraat 14 7554 TS Hengelo 0900-273-8446
airmiles,miepmeijer19,miep02,http://www.airmiles.nl,ponsnummer op kaartje: 6009150 110439813 7; airmilesnummer: 110439813
Amazon,robmeyer,hattam,http://www.amazon.com
ANBO,R.J.Meijer,meij,http://anbo.discount4u.nl,Lidnr: 2205111 Landelijk: Pb 18003 3501 CA Utrecht tel: 030 2330060 email: info@anbo.nl http://www.anbo.nl
anderzorg,robmeyer,xK44fP,http://www.anderzorg.nl,Miep:342364758 Rob:5595420006 BSN:029323083


In line 1 item 5= 4AllClients.com? B.V. Opaalstraat 14 7554 TS Hengelo 0900-273-8446
In line 4 item 5 = Lidnr: 2205111 Landelijk: Pb 18003 3501 CA Utrecht tel: 030 2330060 email: info@anbo.nl http://www.anbo.nl
In line 6 item 5 = Miep:342364758 Rob:5595420006 BSN:029323083

I hope this answers your question and sure you can tell me what to do with the script:
get selectedtext of fld "index"
get lineoffset(it, fld "index")
get line it of field "DB1" of cd "DB"
put item 5 of it into myVar
repeat with i = 1 to wordoffset myVar ???????????
put item i of myVar &cr after tVar
end repeat
put tVar into fld "note"

Thanks, Rob

Re: the text I want

Posted: Sat May 31, 2014 12:44 pm
by Klaus
Hi Rob,

so you also have different formats for the data in "item 5"?
That does not really make this easier... 8)

Any other specifications or general rules how the "item 5"s are structured?
I mean, for item 5 of line 4 you could do something like this:
...
put item 5 of line 4 of tCompleteData into tData
## the TAB is optional, but will make the data look better! :D
replace "Lidnr: " with "Lidnr:" & TAB in tData
replace " Landelijk: " with (CR & "Landelijk:" & TAB & CR) in tData
replace " tel: " with (CR & "tel:":2 & TAB & CR) in tData
replace " email: " with (CR & "email:" & TAB & CR) in tData
put tData into fld "xyz"
...

The same can be applied to "item 5 of line 6", and you can see that this is
no complicated algorithm but just a bit of "naturally" thinking. :D

But I do not see any similar structure we could use for "item 5 of line 1"!?


Best

Klaus

Re: the text I want

Posted: Sat May 31, 2014 2:36 pm
by robm80
But I do not see any similar structure we could use for "item 5 of line 1"!?
So, end of the story !!!

Re: the text I want

Posted: Sat May 31, 2014 3:47 pm
by Klaus
robm80 wrote:
But I do not see any similar structure we could use for "item 5 of line 1"!?
So, end of the story !!!
Mijnheer? :shock:

Re: the text I want

Posted: Sat May 31, 2014 3:58 pm
by robm80
I don't know who has to be shocked?
But: why not introducing in Livecode the function Itemcount() and wordcount():

Syntax itemCount(<expression>)
Parameter <expression
Any expression that yields a list of zero or more items. Literal expressions must be enclosed in quotation marks.
Description Returns the number of items in a list.

In this way my problem would be solved by:
set itc to itemcount(item 5 of line it)
repeat with i = 1 to itc
put item i of myVar &cr after tVar
end repeat
put tVar into fld "note"

Dreamcode ?? 8)

Re: the text I want

Posted: Sat May 31, 2014 4:44 pm
by Klaus
Dag Rob,

hm, you can define the ITEMDELIMITER and the DEFAULT itemdelimiter is a COMMA.
and you can easily create you own itemcount() and wordcount() functions,
see below for a quick excample

Code: Select all

...
set itemdel to ","
put item 5 of line it into tData
## DO not use IT if possible, put It into a variable immediately!

set itemdel to X 
## You need to decide what the necdessary itemdel is in your case!

put the num of items of tData into itc
repeat with i = 1 to itc
  put item i of tData &cr after tVar
end repeat
put tVar into fld "note"
...
For your convenience :D

Code: Select all

## You provide your expression and optionally another itemdelimiter!
function itemcount tExpression,tItemdel
  if tItemdel <> empty then
    set itemdel to tItemdel
  end if
  return the num of ITEMS of tExpression
end itemcount
Usage
...
put itemcount(aVariableWithTextInIt,TAB) into tNumOfTABItems
...

Code: Select all

## Check the dictionary about how WORDS are delimited/counted.
function wordcount tExpression
  return the num of WORDS of tExpression
end itemcount
Best

Klaus

Re: the text I want

Posted: Sat May 31, 2014 6:57 pm
by robm80
Here is the new script:

on mouseUp
get selectedtext of me
put lineoffset(it, me) into tLO
put item 1 of line tLO of field "DB1" of cd "DB" into field "pagnam"
put item 2 of line tLO of field "DB1" of cd "DB" into field "username"
put item 3 of line tLO of field "DB1" of cd "DB" into fld"password"
put item 4 of line tLO of field "DB1" of cd "DB"into field "url"
set itemdel to ","
put item 5 of line tLO of field "DB1" of cd "DB"into tData
put the num of items of tData into itc
repeat with i = 1 to itc
put item i of tData &cr after tVar
end repeat
put tVar into fld "note"
end mouseUp

Well, it goes wrong with " put the num of items of tData into itc"
Itc is always 1

Here is (f.i) Line 1 again:
4allclients,robmeyer@hetnet.nl,11220076,https://www.4allclients.com, 4AllClients.com? B.V.Opaalstraat 14 7554 TS Hengelo 0900-273-8446

Re: the text I want

Posted: Sat May 31, 2014 7:10 pm
by Klaus
Well this line:
4AllClients.com? B.V.Opaalstraat 14 7554 TS Hengelo 0900-273-8446
does not contain any COMMA, so what do you exspect when asking for the num of items! 8)

The big question is: How are the data DELIMITED here?

Re: the text I want

Posted: Sat May 31, 2014 10:18 pm
by robm80
The big question is: How are the data DELIMITED here?
Here is the same line now with comma's.
4allclients,robmeyer@hetnet.nl,11220076,https://www.4allclients.com, 4AllClients.com? B.V., Opaalstraat 14, 7554 TS Hengelo, 0900-273-8446
Problem now is:

get selectedtext of me
put lineoffset(it, me) into tLO
put item 1 of line tLO of field "DB1" of cd "DB" into field "pagnam"
put item 2 of line tLO of field "DB1" of cd "DB" into field "username"
put item 3 of line tLO of field "DB1" of cd "DB" into fld"password"
put item 4 of line tLO of field "DB1" of cd "DB"into field "url"
set itemdel to ","
put item 5 of line tLO of field "DB1" of cd "DB"into tData PROBLEM: item 5 =4AllClients.com? B.V.,
put the num of items of tData into itc
repeat with i = 1 to itc
put item i of tData &cr after tVar
end repeat
put tVar into fld "note"

So, how do I get the other items (Opaalstraat 14, 7554 TS Hengelo, 0900-273-8446) into tData
I hope you understand my problem:put item 5 of line tLO of field "DB1" of cd "DB"into tData in fact should be Put item 5 and the rest of the line into tData.

Thanks,Rob

Re: the text I want

Posted: Sat May 31, 2014 10:20 pm
by Simon
Arrrg!

Code: Select all

on mouseUp
   put "" into fld 1
   put "Lidnr: 2205111 Landelijk: Pb 18003 3501 CA Utrecht tel: 030 2330060 email:info@anbo.nl http://www.anbo.nl" into tData
   put "Lidnr:,Landelijk:,tel:,email:,http://" into myVar
   repeat with x = 1 to the number of items in myVar
      put wordOffset(item x of myVar, tData) into tStart
      put wordOffset(item (x+1) of myVar, tData) into tEnd
      put word tStart to (tEnd -1) of tData & cr after fld 1
   end repeat
   delete the last char of fld 1
end mouseUp
With the given information that works.

Simon
Edit: I see there is new info