Problem with repeat until loop

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Bruce Underwood
Posts: 8
Joined: Thu Oct 23, 2008 12:10 pm
Location: Victoria, VA, USA
Contact:

Problem with repeat until loop

Post by Bruce Underwood » Sun Nov 02, 2008 5:35 pm

I am using the following code in one of my projects, and it does'nt work:


on mouseUp
put 1 into F
repeat until F=7
get char 1 to 6 of field "flowernumber"
put it into mynum
get char 1 to 6 of field "dat1" of stack "flowerdb"
put it into yournum
if mynum=yournum then
get char 1 to 85 of field "dat1" of stack "flowerdb"
put it into field "reportt" of stack "entrypage"
go to stack "entrypage"
else
put "" into field "rang"
put "" into field "reportt"
get char 1 to 6 of field "flowernumber"
put it into C
get char 4 of dat1
put it into B
put ( B + 1) into F
put F into field "rang" of stack "entrypage"
put "No match could be found for entry number" &C into field "reportt"
go to stack "entrypage"
end if
end repeat
end mouseUp

If I remove the repeat loop the code works just fine. The problem is with the command "repeat until F = 7" , but I don't know how to fix it.

I appreciate any help I can get.

Willie Bruce Underwood
bruceu@embarqmail.com
Bruce Underwood
1457 Nutbush Road
Victoria, VA 23974
bruceu@embarqmail.com
Telephone: (434) 696-5539

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Post by mwieder » Tue Nov 04, 2008 11:22 pm

Bruce-

I'm not quite sure what you're trying to accomplish here, but I can see a few problems with whatever you're aiming at:

first of all, "get char 4 of dat1"... there's no dat1 variable, so I'll assume you mean the field named "dat1". You're always getting char 4 without changing the index, so F will *never* be 7. Do you mean to increment the index each time through the loop?

get char x of field "dat1"
add 1 to x

Also - if mynum=yournum then F will *never* be 7, so you'll be stuck in an endless loop.

The same sort of thing goes for putting char 1 to 6 of field "flowernumber" into C - that never changes. And there's really no need for the C variable, since you've got the same contents in mynum.

You'll find the loop runs faster if you take the nonvariant things outside the loop. Here's my take on what I think you're trying to do (but notice that this will still be an endless loop if there's no "6" in field "dat1"):

on mouseUp
local F
local mynum, yournum
local x

put 1 into F
put char 1 to 6 of field "flowernumber" into mynum
put char 1 to 6 of field "dat1" of stack "flowerdb" into yournum

put 4 into x
repeat until F=7
if mynum=yournum then
get char 1 to 85 of field "dat1" of stack "flowerdb"
put it into field "reportt" of stack "entrypage"
exit repeat
else
put "" into field "rang"
put "" into field "reportt"
put char x of field "dat1" + 1 into F
add 1 to x
put F into field "rang" of stack "entrypage"
put "No match could be found for entry number" & mynum into field "reportt"
end if
end repeat
go to stack "entrypage"
end mouseUp

Post Reply

Return to “Mac OS”