Finding an item number

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Finding an item number

Post by gyroscope » Tue Jan 06, 2009 12:31 am

Hi, I've jumped projects again (as I tend to do) and for this particular project, I'm using Custom Properties to save text data. I've based my script on a good stack I found in RevOnline. That all works fine except it loads one line from each field.

So I've been thrashing about trying to come up with a way to retrieve/save multiple lines from each field. For retrieving, my thinking is that when the user selects a particular line in a list box, then if I could find that particular string in the field with the data saved as the custom property, then the next amount of items could easily be put into the relevant fields.

So here's my clumsy code (in the list field):

Code: Select all

on mouseUp pMouseBtnNo
       set itemdel to "#"
put the selectedText of me into Thisone
find Thisone in field "Main"
  put the number of item Thisone in field "Main" into tCount
  put item tCount into field "A"
put item tCount + 1 into field "B"
put item tCount + 2 into field "C"
end mouseUp
The basic problem with this is I don't know how to find the item number within the field "Main" of the string taken from field "Choice". (i.e my code "put the number of item Thisone in field "Main" into tCount" doesn't work...) Could anyone advise me please :?:

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Tue Jan 06, 2009 1:03 am

hi gyroscope,
look for itemOffset(itemToFind,stringToSearch[,itemsToSkip])
I dont really understand how you get the selection etc
this works, kind of, in a button

Code: Select all

on mouseUp
    set itemdel to "#" 
    put the selectedtext of field "choice" into Thisone 
    put itemoffset(Thisone,field "main") into tCount
    put item tCount of field "main" into field "A" 
    put item tCount + 1 of field "main" into field "B" 
    put item tCount + 2 of field "main" into field "C" 
end mouseUp
watch out for multiple occurences of the item, without the skip you always find the first one
maybe you would like to post a sample of your data and stack in revonline
cheers
bernd

Janschenkel
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 977
Joined: Sat Apr 08, 2006 7:47 am
Contact:

Post by Janschenkel » Tue Jan 06, 2009 7:00 am

If your list is showing all the items in the same sequence as your complete data container field, it can be as simple as

Code: Select all

on selectionChanged
  put the hilitedLine of me into ThisLine
  put line ThisLine of field "Main" into ThisLineData
  -- now extract items out of of ThisLineData to populate your fields
  set the itemDelimiter to "#"
  put item 1 of ThisLineData into field 1
end selectionChanged
However, if the lines in your list field are in a different sequence, you're best off using the lineOffset function to find the exact line on which your data is.

Code: Select all

on selectionChanged
  put line (the hilitedLine of me) of me into ThisLine
  put line lineOffset(ThisLine & "#", field "Main") of field "Main" into ThisLineData
  -- now extract items out of of ThisLineData to populate your fields
  set the itemDelimiter to "#"
  put item 1 of ThisLineData into field 1
end selectionChanged
HTH,

Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Sun Feb 01, 2009 10:17 pm

Sincere apologies Bernd and Jan, for my belated reply.

Your scripts help a lot, thank you very much. Your advice and help is always much appreciated.

:)

Post Reply