Clear Data Input Button..?

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

topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Clear Data Input Button..?

Post by topcat888 » Mon Jan 11, 2010 7:20 am

Hi,

If I wanted to have a button to 'undo' the last input to a field "fld1" how would I say that..?

Also if I wanted a button to 'clear' All inputs - i.e. start again, clear all..?

One more question, is it possible to have the background of a text label only show on a certain trigger then disappear when not required..?

Thanks

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

Re: Clear Data Input Button..?

Post by Mark » Mon Jan 11, 2010 11:15 am

topcat888,

Could you please provide more extensive explanations of your problems?

1) this is what I am trying to achieve
2) this is what I got so far
3) and this is where I get stuck

That would make it so much easier to answer your questions!

I'll give it a go, I don't know whether my answers are helpful this time.

You can use the undo command to undo the most recent input.

Use

Code: Select all

put empty into x
to clear a variable. Replace x with a field reference to clear a field.

I am sure you can script the appearance of a label field and make it's background change. For example, change the backColor of the label field. Maybe you mean something else and want to set the style of the label field to transparent or opaque.

Best 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

topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Re: Clear Data Input Button..?

Post by topcat888 » Mon Jan 11, 2010 6:55 pm

Hi Mark,

Thanks for your reply. The reason this question seems out of context is because it 'was' at the bottom of my 'Moving Numbers' post but received no reply so I started a new post in the hope of getting a reply.!

I am aware of the put empty into x but in this instance it is not applicable because whilst it does remove the last entry, when a new number is entered it does not over write the 'blank space' created by put empty into x, instead it is carried along from field to field which is obviously no good..? In other words the new number does not over write the blank field, the 'blank' is carried along from field 1 to field 2,3,4 and 5 as actual number/entry which is obviously isn't..?

The next question related to to the clearance of 'All' user entered data, in other words a 'Clear All' - 'Start Again' button..?

I will try the 'backColor' to script the colour change of a text field...

Thanks for your help,

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

Re: Clear Data Input Button..?

Post by bn » Mon Jan 11, 2010 7:07 pm

TopCat,
if you want to clear several buttons then in a repeat loop you could say put empty into field x.

Code: Select all

on mouseUp
repeat with i = 1 to the number of fields
   put empty into field i
end repeat
end mouseUp
If I remember then you had 4 fields that are filled from right to left. If you want to have some sort of memory of the last that was pushed out of the leftmost field you could put field 4 into a hidden field 5 that has the advantage that you can easily make a undo by shifting the numbers back from field 5 (the number that was pushed off) into field 4 and so on. Of course you would start with field 2 that goes into field 1 and 3 into field 2 ... you get the idea.

regards
Bernd

topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Re: Clear Data Input Button..?

Post by topcat888 » Mon Jan 11, 2010 8:53 pm

Hi Bernd,

Thanks for the reply, I hadn't thought of doing it like that, moving all numbers back one, very novel idea... I was thinking that simply the number that was last input (into the first field) could be erased ready to accept a new one..?

If I was to implement your way of doing it, I would use a simple push button to move all number back one field... how would I say that in code..?

Thanks

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

Re: Clear Data Input Button..?

Post by bn » Mon Jan 11, 2010 9:18 pm

TopCat,

suppose you have the 5 fields I mentioned, 4 for display and 1 for the 'overflow'
they are named "disp1,disp2,disp3,disp4,disp5" disp1 being the rightmost, accepting the latest user input and pushing older inputs to disp2, disp3 etc.

Code: Select all

on mouseUp
   put "disp1,disp2,disp3,disp4,disp5" into tListOfFields
   repeat with i = 2 to the number of items of tListOfFields
      put field (item i of tListOfFields) into field (item i - 1 of tListOfFields) 
   end repeat
end mouseUp
Now you have shifted the content by one field, you have to catch that the user does not click repeatedly, this would have field disp5 filling up all the other fields.
Thanks for the reply, I hadn't thought of doing it like that, moving all numbers back one, very novel idea... I was thinking that simply the number that was last input (into the first field) could be erased ready to accept a new one..?
in my opinion it all depends on your user interface. You can do it either way. From what I remember when the user clicks it puts the number into what I call field "disp1" if the information in the other fields is still relevant to the user and he might just go back one step then I would move the numbers for the user to have the state "one click before"
If not you could just put empty into the field.
regards
Bernd

topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Re: Clear Data Input Button..?

Post by topcat888 » Mon Jan 11, 2010 11:59 pm

If not you could just put empty into the field.
Thats the problem with that way, if you put empty into fld1 (the first field to be entered) then when the user presses the new number, instead of the blank field being populated by the new number the 'blank' moves one field to the left (field 2) and the new number is put into field 1... see the problem..? I would still like to have the choice of either of these ways, but this one is not right yet..?

Out of interest is there a way to stop the user 'clicking' past a certain number of back clicks, i.e. after clicking the back button for x numbers of clicks it does nothing..?

Thanks

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

Re: Clear Data Input Button..?

Post by bn » Tue Jan 12, 2010 12:26 am

TopCat,
Is there a way to stop the user keep clicking past a certain number of back clicks, i.e. after clicking the back button for x numbers of clicks it does nothing..?
you can do that in different ways. My preferred way would be to make a custom property for the button. It sounds complicated but is just some storage you can attack to every object in Rev. It is persistent i.e. it is stored with the stack. You create one simply by issueing a command like this:

Code: Select all

set the uUndoCounter of me to the uUndoCounter of me +1
uUndoCounter is a name you are free to choose as long as it is not a reserved word. By issueing the command you create the custom property. You can access the private property from other objects.
So you could set this property from your undo button and test whether the number is within the range you want. In your script that fills the field in the normal mode you can then reset that counter because now you have something to 'undo' again.

I made a little stack that shows you what I mean.
regards
Bernd
undoCounter.rev.zip
sample stack for custom property
(1005 Bytes) Downloaded 278 times

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

Re: Clear Data Input Button..?

Post by bn » Tue Jan 12, 2010 12:36 am

topcat,
new number the 'blank' moves one field to the left (field 2) and the new number is put into field 1... see the problem..? I would still like to have the choice of either of these ways, but this one is not right yet..?
you can always in your populating script test for a blank field and if the field is bland adjust your populating accordingly.

Code: Select all

if field 1 is empty  then
--do the part for the empty field
else
--do the normal part
end if
Without knowing your script it is difficult to be more precise, but by now you are an experienced Rev programmer anyways :wink: , so not sweat
regards
Bernd

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

Re: Clear Data Input Button..?

Post by bn » Tue Jan 12, 2010 12:43 am

TopCat,
I forgot to mention explicitly that the syntax for properties and also custom properties in Rev is a little different from the normal container syntax.
You say e.g. for setting a backgroundcolor: set the backgroundColor of field 1 to blue
Likewise for a custom property you say: set the uUndoCounter of button 1 to 10
You have to use the set syntax. You can not 'put' anything into a property or custom property.
regards
Bernd

topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Re: Clear Data Input Button..?

Post by topcat888 » Tue Jan 12, 2010 8:10 am

Hi Bernd,

Thankyou for your advise. I have done this so far but it does not work properly:

Code: Select all

    if the target contains "button" then
      put the label of the target into tLabel
      if tLabel > 0 and tLabel < 13 then put "L" into field "fld1"
      if tLabel > 12 and tLabel < 25 then put "M" into field "fld1"
      if tLabel > 24 and tLabel < 37 then put "H" into field "fld1" 
      else
         put field "fld3" into field "fld4"
         put field "fld2" into field "fld3"
         put field "fld1" into field "fld2"
      end if
   end if
   
   if the target contains "button" then
      put tLabel into field "lastNum1"    
   else
      put field "lastNum17" into field "lastNum18"
      put field "lastNum16" into field "lastNum17"
      put field "lastNum15" into field "lastNum16"
      put field "lastNum14" into field "lastNum15"
      put field "lastNum13" into field "lastNum14"
      put field "lastNum12" into field "lastNum13"
      put field "lastNum11" into field "lastNum12"
      put field "lastNum10" into field "lastNum11"
      put field "lastNum9" into field "lastNum10"
      put field "lastNum8" into field "lastNum9"
      put field "lastNum7" into field "lastNum8"  
      put field "lastNum6" into field "lastNum7"
      put field "lastNum5" into field "lastNum6"
      put field "lastNum4" into field "lastNum5"  
      put field "lastNum3" into field "lastNum4"
      put field "lastNum2" into field "lastNum3"
      put field "lastNum1" into field "lastNum2"
   end if
Can you see anything that is obviously wrong..?

Thanks

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Clear Data Input Button..?

Post by Klaus » Tue Jan 12, 2010 11:59 am

Hi topcat,

what exactly do you mean with "does not work properly"? Does it work, but not as exspected, do you get an error, if yes which one etc.
Please, please, please, we need a bit more specific info!

Your script looks OK, but WHERE (button/card/stack) is that handler?
I do not see "on mouseup" or something.


Best

Klaus

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

Re: Clear Data Input Button..?

Post by bn » Tue Jan 12, 2010 12:04 pm

TopCat,

Please explain what the code is supposed to do. What should happen when? I don't know the logic of your stack and there is more then one source of error. What do you expect and what happens instead?

regards
Bernd

topcat888
Posts: 44
Joined: Sat Jan 02, 2010 8:10 pm

Re: Clear Data Input Button..?

Post by topcat888 » Tue Jan 12, 2010 6:35 pm

Hi

Sorry, the problem is that the clear last number now works perfectly (using Bernd code)

Code: Select all

if field 1 is empty  then
--do the part for the empty field
else
--do the normal part
end if
But there is a problem when you press a another button (to enter a new number into field 1) it duplicates the new number placing it in field 2 at the same time, every time...

This is all the code:

Code: Select all

on mouseup
   
   if the target contains "button" then
      put the label of the target into tLabel
      if tLabel = 0 then put "Z" into field "fld1"
      if tLabel > 0 and tLabel < 13 then put "L" into field "fld1"
      if tLabel > 12 and tLabel < 25 then put "M" into field "fld1"
      if tLabel > 24 and tLabel < 37 then put "H" into field "fld1" 
      else
         put field "fld3" into field "fld4"
         put field "fld2" into field "fld3"
         put field "fld1" into field "fld2"
      end if
   end if
   
   if the target contains "button" then
      put field "lastNum17" into field "lastNum18"
      put field "lastNum16" into field "lastNum17"
      put field "lastNum15" into field "lastNum16"
      put field "lastNum14" into field "lastNum15"
      put field "lastNum13" into field "lastNum14"
      put field "lastNum12" into field "lastNum13"
      put field "lastNum11" into field "lastNum12"
      put field "lastNum10" into field "lastNum11"
      put field "lastNum9" into field "lastNum10"
      put field "lastNum8" into field "lastNum9"
      put field "lastNum7" into field "lastNum8"  
      put field "lastNum6" into field "lastNum7"
      put field "lastNum5" into field "lastNum6"
      put field "lastNum4" into field "lastNum5"  
      put field "lastNum3" into field "lastNum4"
      put field "lastNum2" into field "lastNum3"
      put field "lastNum1" into field "lastNum2"
   else
      put tLabel into field "lastNum1" 
   end if
   end mouseUp
Thanks

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

Re: Clear Data Input Button..?

Post by bn » Tue Jan 12, 2010 7:00 pm

TopCat,
I give it a try:

Code: Select all

on mouseup
   
   if the target contains "button" then
      put the label of the target into tLabel
      
      -- test for your range of interest
      -- between 0 and 36 and only then do the following
      if tLabel >-1 and tLabel < 37 then
         
         -- do your field shuffling before putting 
         -- the new value into "fld1" otherwise the new value would 
         -- be shifted to fld2 every time
         put field "fld3" into field "fld4"
         put field "fld2" into field "fld3"
         put field "fld1" into field "fld2"
         
         if tLabel = 0 then put "Z" into field "fld1"
         if tLabel > 0 and tLabel < 13 then put "L" into field "fld1"
         if tLabel > 12 and tLabel < 25 then put "M" into field "fld1"
         if tLabel > 24 and tLabel < 37 then put "H" into field "fld1" 
         
         put field "lastNum17" into field "lastNum18"
         put field "lastNum16" into field "lastNum17"
         put field "lastNum15" into field "lastNum16"
         put field "lastNum14" into field "lastNum15"
         put field "lastNum13" into field "lastNum14"
         put field "lastNum12" into field "lastNum13"
         put field "lastNum11" into field "lastNum12"
         put field "lastNum10" into field "lastNum11"
         put field "lastNum9" into field "lastNum10"
         put field "lastNum8" into field "lastNum9"
         put field "lastNum7" into field "lastNum8"  
         put field "lastNum6" into field "lastNum7"
         put field "lastNum5" into field "lastNum6"
         put field "lastNum4" into field "lastNum5"  
         put field "lastNum3" into field "lastNum4"
         put field "lastNum2" into field "lastNum3"
         put field "lastNum1" into field "lastNum2"
         put tLabel into field "lastNum1" 
      else
         --
         -- if you have anything that should happen if 
         -- tLabel outside of 0 .... 36 then insert it here 
         -- or delete the else part
      end if
end mouseUp
if you have problems with this tell us about it. To me it is still not completely clear what you want but here it goes.
regards
Bernd

Post Reply