Am I missing something

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: heatherlaine, Klaus, FourthWorld, kevinmiller

Post Reply
JosephCBW
Posts: 3
Joined: Wed Nov 07, 2018 3:50 pm

Am I missing something

Post by JosephCBW » Wed Nov 07, 2018 4:08 pm

to give you an idea of what this is doing.
44 source fields with 1 character in each field. (SK fields)
I have 10 user entered fields (with values from 1-44 entered by the user). (PIK Fields)
44 final (we will call user swapped) fields (BK Fields)

When a user enters a string of 10 numbers into the PIK fields it will trigger what I thought was going to be a simple copy and paste string of events.
if the text of field PIK_1 = "2" then
select the text of field SK_2
copy
select the text of field swap2
paste
else
if the text of field PIK_1 = "3" then
select the text of field SK_3
copy
select the text of field swap2
paste
(ETC to PIK_44)

That part works.

My issue is getting the swap 1 and 2 to copy and paste from their areas Swap1 and swap2 to the BK fields.

here is that code. At the moment I have them triggered with buttons so that I can figure this out. I would really like it to ultimately be a part of the script so that its seamless.. say when the #10 field is exited. but at this point I am open to any suggestions.

here is that part of the script.

if the text of field PIK_1 = "1" then
select the text of field swap1
copy
select the text of field BK_1
paste
else
if the text of field PIK_1 = “2” then
select the text of field swap1
copy
select the text of field BK_2
paste
else
so on and so on to PIK_1 = 44

there may be a shorter way to do this since running 44 steps on each of the 10 fields may be overkill. but this is where I am at currently.

Any ideas.

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

Re: Am I missing something

Post by Klaus » Wed Nov 07, 2018 5:08 pm

Hi Joseph,

hello and welcome to the forum! 8)

Not sure I understand you completely, but maybe this is what you are looking for:

Code: Select all

...
  lock screen
  repeat with i = 1 to 44
      if the text of fld "PIK_1" = i then
         put fld ("SK_" & i + 1) into fld "SWAP_2"
      end if
   end repeat
   unlock screen
...
If that is not what you need, please explain where I was wrong. :D

Some helpful hints:
By using "lock/unlock screen", this is lightning fast and can be triggered anytime if neccessary, give it a try.
No need to copy/select/paste, simply "put"ting text INTO a field will overwrite its previous content, if any.
Get used to put Quotes around object names and everything that is a "string".

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Am I missing something

Post by dunbarx » Wed Nov 07, 2018 5:21 pm

Hi.

Welcome to the forum.

We will get through this.

In future, place all your handlers into the handler gadget ("</>")

There are several ways to shorten your handler, for example:

Code: Select all

select the text of field SK_2
copy
select the text of field swap2
paste
could be changed to:

Code: Select all

put field "SK_2" into field "swap2"
but that is for later.

My problem is that I cannot test your handler snippets without actually building some or all of the fields. And there may be other issues, since the handlers you gave are not complete.

We will get through this. Write back with more information.

Craig Newman

JosephCBW
Posts: 3
Joined: Wed Nov 07, 2018 3:50 pm

Re: Am I missing something

Post by JosephCBW » Wed Nov 07, 2018 5:38 pm

Klaus wrote:
Wed Nov 07, 2018 5:08 pm
Hi Joseph,

hello and welcome to the forum! 8)

Not sure I understand you completely, but maybe this is what you are looking for:

Code: Select all

...
  lock screen
  repeat with i = 1 to 44
      if the text of fld "PIK_1" = i then
         put fld ("SK_" & i + 1) into fld "SWAP_2"
      end if
   end repeat
   unlock screen
...
If that is not what you need, please explain where I was wrong. :D

Some helpful hints:
By using "lock/unlock screen", this is lightning fast and can be triggered anytime if neccessary, give it a try.
No need to copy/select/paste, simply "put"ting text INTO a field will overwrite its previous content, if any.
Get used to put Quotes around object names and everything that is a "string".

Best

Klaus

Klaus

This worked!! loads of time saved copy and pasting.. I just changed the destination of from SK, to the BK is there way to put 2 variables into this? After its done with PIK_1, run the same on PIK_3

Code: Select all

lock screen
repeat with i = 1 to 44
   if the text of fld "PIK_1" = i then
      put fld swap2 into fld ("BK_" & i + 1)
   end if
end repeat
unlock screen
that is working on PIK 1, is there way way to to the same to PIK 3 after this is done and pull from swap1

I tried to add the variable under it like this

Code: Select all

lock screen
repeat with i = 1 to 44
   if the text of fld "PIK_1" = i then
      put fld swap2 into fld ("BK_" & i + 1)
   end if
end repeat

repeat with i = 1 to 44
   if the text of fld "PIK_3" = i then
      put fld swap1 into fld ("BK_" & i + 1)
   end if
end repeat
unlock screen
but it stopped at PIK_1

Thanks

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

Re: Am I missing something

Post by Klaus » Wed Nov 07, 2018 5:49 pm

Hi Joseph,

so the first loop actually works?
What exactly happend when "it stopped at PIK_1"?
Did you see an error? Or does this just not happen?
And do you really have a field named -> BK_45 ?


BTW:
You overwrite the same fields in both loops -> fld ("BK_" & i + 1)


Beest

Klaus

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

Re: Am I missing something

Post by Klaus » Wed Nov 07, 2018 6:11 pm

Ah, I overlooked:
is there way to put 2 variables into this?
Do like this:

Code: Select all

...
lock screen
repeat with i = 1 to 44
   if the text of fld "PIK_1" = i then
     ## QUOTES! 8)
      put fld "swap2" into fld ("BK_" & i + 1)
   end if
   
  ## Why start another loop? :-)
  
   if the text of fld "PIK_3" = i then
      put fld "swap1" AFTER fld ("BK_" & i + 1)
      ## Add space
      ## OR: put " " & fld "swap1" AFTER fld ...
      ## Or put variable at the beginning of field
      ## OR: ... BEFORE fld ...
      ## Add a new line 
      ## OR: ... CR & fld "swap1" AFTER fld ...
      ## You get the picture :)
   end if
end repeat
unlock screen
...

JosephCBW
Posts: 3
Joined: Wed Nov 07, 2018 3:50 pm

Re: Am I missing something

Post by JosephCBW » Wed Nov 07, 2018 6:26 pm

no fields PIK 1 and 3 are the 2 that I want to be linked really in this script..

when I ran the script that I posted with both it just ran the PIK_1 area but just nothing on the PIK_3

ideally it should replace the contents of corresponding user entered numbers on PIK 1 and 3

say they enter 33 into PIK_1 and 19 into PIK_3

it should replace the contents of BK_1 with field contents swap2 and BK_3 with swap1

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

Re: Am I missing something

Post by Klaus » Wed Nov 07, 2018 6:34 pm

I just used your example script, since I have no idea what you really want.

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

Re: Am I missing something

Post by Klaus » Wed Nov 07, 2018 6:35 pm

And what does "when I ran the script that I posted with both it just ran the PIK_1 area but just nothing on the PIK_3" mean? See my previous but one posting with all these questions. :D

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”