number of items?

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
tusa
Posts: 36
Joined: Sun Jan 31, 2016 10:30 pm

number of items?

Post by tusa » Wed Mar 22, 2017 11:01 am

Can I count the numbers of items after setting the item delimiter?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: number of items?

Post by jmburnod » Wed Mar 22, 2017 11:22 am

Hi Tusa,
Yes we can.

Code: Select all

on mouseUp
   put "A_B_C" into tVar
   set the itemdel to "_"
   put the num of items of tVar into tNbItems
   set the itemdel to ","-- dont forget this
   answer "Num of items of tVar =" && tNbItems
end mouseUp
Best regards
Jean-Marc
https://alternatic.ch

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: number of items?

Post by Klaus » Wed Mar 22, 2017 12:05 pm

Hi Jean-Marc,

the itemdelimiter is a LOCAL property and will automatically be reset to COMMA
after a handler is finished, so no need for this in your example!


Best

Klaus

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: number of items?

Post by Klaus » Wed Mar 22, 2017 12:15 pm

Hi Tue,
tusa wrote:Can I count the numbers of items after setting the item delimiter?
as Jean-Marc already said, yes, this is surely possible!
You can even swith itemdelimiters to your needs inside of a handler!

To reference your previous (and obviously deleted) posting :D :

Code: Select all

...
put line 2 of the dgtext of grp "my wonderful datagrid" into aVar

## tVar now contains X number of items with TAB delimited
set itemdel to TAB
repeat with i= 1 to the num of items of tVar
   put item i of tVar into tVar2
   set itemdel to ";"
   put "The num of items delimited with ; in item 1 of tVar = " & the num of items of tVar2 & CR after fld "Item info"
   
   ## IMPORTANT or the repeat loop will break:
   set itemdel to TAB
end repeat
...
Hint:
"the num of items" will be 1 even if there is NO itemdelimiter at all in the string to examine!


Best

Klaus

tusa
Posts: 36
Joined: Sun Jan 31, 2016 10:30 pm

Re: number of items?

Post by tusa » Wed Mar 22, 2017 2:35 pm

Thank you, that solved my problem.
I did only use part of your suggestion, but that was what I needed.

Post Reply

Return to “Talking LiveCode”