How to pick selection in a field?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
22c304
Posts: 3
Joined: Fri Nov 12, 2010 3:32 pm

How to pick selection in a field?

Post by 22c304 » Fri Nov 12, 2010 3:41 pm

Hello everyone ....

I must be missing something really simple.
I know I can do this with a button using label, however .....
I have a field defined that contains three values (1st, 2nd,3rd) in Contents
The field has a vertical scrollbar and scrolls/shows the three values properly. I want to write an if statement based on the current value of the field. How do i get the value of this field?

Thanks for any suggestions ..


Wes

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: How to pick selection in a field?

Post by shaosean » Fri Nov 12, 2010 4:47 pm

If you have a button and a list field named "list" you can place the following code in the button to get the selected text of the field.

Code: Select all

on mouseUp
  put the selectedText of field "list"  -- displays the selected text in the message box
end mouseUp
Now if you want to use this in an "if" statement

Code: Select all

on mouseUp
  if (the selectedText of field "list" = "1st") then
    -- do first stuff
  else if (the selectedText of field "list" = "2nd") then
    -- do second stuff
  else if (the selectedText of field "list" = "3rd") then
    -- do third stuff
  end if
end mouseUp
You can also use a "switch" statement instead of an "if" statement

Code: Select all

on mouseUp
  switch (the selectedText of field "list")
  case "1st"
    -- do first stuff
    break  -- this breaks out of the case; if this is missing it will do the statements in the next case
  case "2nd"
    -- do second stuff
    break  -- this breaks out of the case; if this is missing it will do the statements in the next case
  case "3rd"
    -- do third stuff
    break  -- this breaks out of the case; if this is missing it will do the statements in the next case
  end switch
end mouseUp

22c304
Posts: 3
Joined: Fri Nov 12, 2010 3:32 pm

Re: How to pick selection in a field?

Post by 22c304 » Fri Nov 12, 2010 8:13 pm

Thanks for the reply......

I understand case and if, that is not a problem.

I was trying to use a text entry field with a scroll property, NOT a list field. Can you case a text entry field for the current value?

There is no selectedtext or insertion point

Thanks........

Wes

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How to pick selection in a field?

Post by Mark » Fri Nov 12, 2010 11:22 pm

Hi Wes,

Your problem is not: how do I get some value of some field in some way, but rather how do I design a useful and functional interface. What you are trying to accomplish doesn't make sense. Please, redesign your interface.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

22c304
Posts: 3
Joined: Fri Nov 12, 2010 3:32 pm

Re: How to pick selection in a field?

Post by 22c304 » Sat Nov 13, 2010 2:18 am

Mark

FYI I was not planning on using this in a interface. I used a button to accomplish wgat i needed. But i wanted to know how it could be done in runrev. I was curious how to do it. As in why can you make a text entry field have multiple values if you cannot case the current selection/option.

Your reply seemed more of a opinion than an answer.

Wes

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: How to pick selection in a field?

Post by BvG » Sat Nov 13, 2010 2:47 am

Maybe mark just didn't understand what you actually want to do. Actually, neither do I, but maybe reading the following entries in the dictionary is helpful for you:

selectedText
hilitedText
offset
lineoffset
select


also note that pressing a button does remove the focus from a field, and this means the selection is emptied. to prevent that, set the traversalOn of the button to false.
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Bantymom
Posts: 73
Joined: Fri Aug 27, 2010 4:32 am

Re: How to pick selection in a field?

Post by Bantymom » Sat Nov 13, 2010 3:52 am

I have been following this thread with interest and confusion. Do you have a bit of a stack to show upload (as a zip file)? Do you have, perhaps a screenshot of what it looks like?

Cheers,
Bantymom
2nd-grade Teacher, Poultry Fancier, Scottish Country Dancer
and Perpetual Beginner

Post Reply