Delete item in field chosen from dropdown

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
TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Delete item in field chosen from dropdown

Post by TodayIsTheDay » Sat Oct 10, 2009 10:38 pm

I've tried several versions of this and I'm stumped. All I'm trying to do is to delete an item in a field that I've chosen from a dropdown menu.

I'm using this:

Code: Select all

on menuPick pItemName
   
    delete pItemName from field "Field321"
   
   end menuPick

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Sun Oct 11, 2009 12:15 am

You're on a good start, but you haven't specified a chunk type (the type of thing that you want to act on, line, item, word, character).

Are the items return-delimited? If so this should do it:

Code: Select all

on menuPick pItemName
    set the wholeMatches to true
    put lineoffset(pItemName, field "Field321") into tOS
    if tOS > 0 then
       delete line tOS of field "Field321"
   end if
end menuPick
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Post by TodayIsTheDay » Sun Oct 11, 2009 2:57 am

Thanks. Now added some code. I'm looping through and even able to delete multiple occurrences of it :)

But... With that being said, I don't see exactly how it works...
Could you or someone please tell me how this works?

Code: Select all

--We are setting a local variable called tLineNumber
local tLineNumber

--We are making TLineNumber the number 1
put 1 into tLineNumber

--loops through each line of my field
repeat for each line tLine in field "Very Long List"

--here is where I'm lost. Where did we get tline? I didn't declare it??
   doStuff tLine, tLineNumber

--Why do we have to add 1 to tLineNumber if we've already told it to repeat for each line of my field "Very long list"??
   add 1 to tLineNumber

end repeat

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Post by FourthWorld » Sun Oct 11, 2009 3:29 am

It seems that tLineNumber is updated only for the benefit of the handler doStuff. Without knowing what doStuff does, we don't know why it needs that number.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

TodayIsTheDay
Posts: 56
Joined: Sat Jun 20, 2009 2:41 pm

Post by TodayIsTheDay » Sun Oct 11, 2009 3:35 am

I 'm not sure what it does.... I found the code sample in the notes of the repeat function in the Rev Dictionary.

I modified it as this:

Code: Select all

on menuPick pItemName
   
 set the wholeMatches to true
   
   local tLineNumber

put 1 into tLineNumber

repeat for each line tLine in field "Field321"
  
  put lineoffset(pItemName, field "Field321") into tWordToDelete
    if tWordToDelete > 0 
    then 
       delete line tWordToDelete of field "Field321"
    end if
    
    add 1 to tLineNumber
   
   end repeat
    
end menuPick

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

Post by bn » Sun Oct 11, 2009 10:40 am

TodayIsTheDay,
repeat for each line tLine in field "Very Long List
here you create your variable tLine, that is where it comes from
Why do we have to add 1 to tLineNumber if we've already told it to repeat for each line of my field "Very long list"??
repeat for each line tLine in field...
puts the content of that line into tLine, so tline is all the text of the line, but tLine does not indicate what the line number is. If you need that then you have to make a counter, that is what tLineNumber is for, it just tells you what line number the repeat for each line tLine is working on.
on menuPick pItemName
   
 set the wholeMatches to true
   
   local tLineNumber

put 1 into tLineNumber

repeat for each line tLine in field "Field321"
 
  put lineoffset(pItemName, field "Field321") into tWordToDelete
    if tWordToDelete > 0
    then
       delete line tWordToDelete of field "Field321"
    end if
   
    add 1 to tLineNumber
   
   end repeat
   
end menuPick
here you mix two forms. For what you want to do you dont need the repeat for each line, the repeat and the lineOffset is sufficient. tWordToDelete holds the line number, no need for an additional counter, pItemName holds the word, no need to look at the text of the line in repeat for each line tLine.

Code: Select all

on menuPick pItemName     
   set the wholeMatches to true 
   repeat  
      put lineoffset(pItemName, field "Field321") into tWordToDelete 
      if tWordToDelete > 0 then 
         delete line tWordToDelete of field "Field321" 
      else
         exit repeat -- you are done, no more occurences, get out of the repeat loop
      end if 
   end repeat 
end menuPick


regards
Bernd

Post Reply