Need Help with certain code

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
Taz
Posts: 11
Joined: Mon Aug 20, 2007 9:04 pm

Need Help with certain code

Post by Taz » Wed Aug 22, 2007 12:08 am

Ok, im going to explain this best i can -

THE SCENARIO

Lets say i have 5 small rectangular fields on my stack card.

I create a code, which enables me to put data on each of the fields one by one.

It asks the question "what would you like in this field" and i will type it in.

I get to field 2 out of 5. I then cancel it.

Now, i want to be able to click the execute button again, but start from field 3, instead of all the way to field 1.

Now, i use this command in a repeat code -

Code: Select all

if "field" is not empty then (go back to repeat loop)
the stuff in brackets is the part i don't know... how do i make a repeat loop restart, mid point in the actual repeat script.

I hope you undestand what im trying to say.

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

Post by Mark » Wed Aug 22, 2007 12:53 am

Dear Taz,

Probably, this is what you want:

Code: Select all

repeat with x = 1 to 5
  if fld x is not empty then exit repeat
end repeat
repeat with y = x to 5
  -- do your stuff here
end repeat
Best,

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

Taz
Posts: 11
Joined: Mon Aug 20, 2007 9:04 pm

Post by Taz » Wed Aug 22, 2007 4:58 pm

nope, what that code did was, go through the 5 fields, if it's not empty, it just exits the script.

So say if field 1 has something in it, then instead of skipping it and going to field 2, it jus exits the repeat.

Do you understand what im trying to say

I want it to be able to go down the fields, and know that if the field has something in it, then it must skip to the next field, and if there's nothing in the field, i want it to ask me the question -

"what would u like to input in this field".

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

Post by Mark » Wed Aug 22, 2007 5:10 pm

Taz,

Did you replace "do you stuff" with something else?

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

Taz
Posts: 11
Joined: Mon Aug 20, 2007 9:04 pm

Post by Taz » Wed Aug 22, 2007 5:43 pm

in the do ur stuff part, i placed the actual script there.

The script basically cycles through the fields, and asks me a question, in which i input data, and it inputs it into the field.

so it's like -

Code: Select all

repeat counter = 1 to 5
ask "question here" 
put it into "field"
Now, if the field is not empty, i want it to stop, and skip straight to the next field. If that field is not empty, then i want it to skip again, until it finds an empty field and then asks me to input data into it.

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

Post by BvG » Wed Aug 22, 2007 10:14 pm

Code: Select all

repeat with counter = 1 to 5
  if field counter = "" then
    ask "question here"
    put it into field counter
  end if
end repeat
untested
Various teststacks and stuff:
http://bjoernke.com

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

Taz
Posts: 11
Joined: Mon Aug 20, 2007 9:04 pm

Post by Taz » Thu Aug 23, 2007 12:52 pm

K let me try to explain in another way.

I want to be able to know how to put a "if" or any command, that i could place in the MIDDLE of a repeat loop, to make the repeat loop go from the beginning, instead of carrying on through the script.

malte
Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Contact:

Post by malte » Thu Aug 23, 2007 1:57 pm

Hi Taz,

now I am getting confused. Could you please try to explain exactly what you want to do? (Using bold does not really help me understand your question)

I understood you wanted to examine if a field already has been filled in and if so, continue with the next empty field. Both Marks and Björnkes Script will let you do just that.

However, if you want to go back to the start of the loop, your repeat construct needs to look a bit differently:


on mouseUp
local i
put 1 into i
repeat until i=5
if fld i is not empty then
-- go back to start
put 0 into i
end if
add 1 to i
end repeat
end mouseUp

However, I'm sure what you want is Marks or Björnkes Script. Have you actually tried them?

All the best,

Malte

[edit]Fixed typo.[/edit].

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

Post by Janschenkel » Thu Aug 23, 2007 6:54 pm

Hi Taz,

Would 'next repeat' do the trick? It will skip the rest of the repeat statements and go straighyt back top the beginning - like the 'continue' command in Java.

Code: Select all

on mouseUp
  repeat for each word tWord in field "foobar"
    if tWord is "SKIPTHIS" then next repeat
    -- do whatever you like for other words
    put upper(tWord) & return after field "snafu"
  end repeat
end mouseUp
If you were to execute the above when field "foobar" contains the following:

Code: Select all

If only I could SKIPTHIS - then things would be fine
Then the field "snafu" would contain:

Code: Select all

If
only
I
could
-
then
things
would
be
fine
Hope this helped,

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

Taz
Posts: 11
Joined: Mon Aug 20, 2007 9:04 pm

Post by Taz » Fri Aug 24, 2007 6:43 pm

Thank you very VERY much Janschenkel, that is exactly what i was looking for and wanted.

Code: Select all

next repeat
.

Still much appreciation to maltem, BvG, Mark for all trying to help me.

Sorry for making it sound so complicated :S

Thanks once again.

ThinKolistic
Posts: 5
Joined: Thu Apr 24, 2008 5:54 pm
Contact:

Post by ThinKolistic » Thu May 01, 2008 8:20 pm

Taz wrote:Thank you very VERY much Janschenkel, that is exactly what i was looking for and wanted.

Code: Select all

next repeat
.

Still much appreciation to maltem, BvG, Mark for all trying to help me.

Sorry for making it sound so complicated :S

Thanks once again.
Wouldn't it be great if we could make a video of the behaviour that we hope for: post it on Google Collaborator and link to the forum ?
George Wade
Horseshoe Bay
West Vancouver
"Japanese was easy
RunRev is different..!"

Post Reply