Repeat function not working.

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
CAsba
Posts: 384
Joined: Fri Sep 30, 2022 12:11 pm

Repeat function not working.

Post by CAsba » Thu Mar 23, 2023 1:21 pm

Hi all,
Here's my code:-

Code: Select all

on mouseup
      put 0 into fld "cmsdone" 
   repeat while fld "cmsdone" is 0
      repeat until dimension1 is a number
         ask "Enter the dimension, for example the length, of the product as purchased (numerals only, in centimetres)" titled (fld "fieldboxtitle" of cd "template1")
         put it into dimension1
         if dimension1 is not a number or dimension1 <0 then
            put empty into dimension1
            answer "Try again. You must enter a numeric value above zero" titled (fld "fieldboxtitle" of cd "template1")
         end if
      end repeat
      repeat until cutdimension is a number
         ask "Enter the dimension, for example the length, of the product as used in the product (numerals only, in centimetres)" titled (fld "fieldboxtitle" of cd "template1")
         put it into cutdimension
         if cutdimension is not a number or cutdimension <0 then
            put empty into cutdimension
            answer "Try again. You must enter a numeric value above zero" titled (fld "fieldboxtitle" of cd "template1")
         end if
      end repeat
      repeat until pieces is a number
         ask "Enter the number of these pieces as used in the manufactured product (numerals only)" titled (fld "fieldboxtitle" of cd "template1")
         put it into pieces
         if pieces is not a number or pieces <0 then
            put empty into pieces
            answer "Try again. You must enter a numeric value above zero" titled (fld "fieldboxtitle" of cd "template1")
         end if
      end repeat
      repeat until wastefactor is a number
         ask "Enter the approximate waste factor as a percentage, when producing the pieces for the manufactured product (numerals only)" titled (fld "fieldboxtitle" of cd "template1")
         put it into wastefactor
         if wastefactor is not a number or wastefactor <0 then
            put empty into wastefactor
            answer "Try again. You must enter a numeric value above zero" titled (fld "fieldboxtitle" of cd "template1")
         end if
      end repeat
      put fld "stock" & tab & fld "compcode" & tab & fld "description" & tab & fld "usualquantity" & fld "cost2" & tab & dimension1 & tab & cutdimension & tab & pieces & tab & wastefactor into theText         
      put false into firstLineContainsColumnNames
      dispatch "addline" to grp "DataGrid 1" with theText
      filter rows without empty
      put fld "stock" & tab & fld "codep" & tab & fld "description" & tab & fld "usualquantity" & fld "cost"  & fld "disc"into theText         
      put false into firstLineContainsColumnNames
      dispatch "addline" to grp "DataGrid 1" with theText
      filter rows without empty
      Answer question "Enter another different size piece of this component as a part of the manufactured product ?" with "YES" or "NO" titled field "fieldboxtitle"  of cd "template1"
      if it is "yes" then 
         
      end if
      if it is "NO" then
         put 1 into fld "cmsdone"
      end if                  
      end repeat
I know it's a bit long, but I copied it in full just in case the length might be the problem, which is..

User answers "No", not a problem, everything stops.

User answers "Yes", I expected the whole shooting match to repeat from the top; what I get is a repeat of the question, "Enter another different size piece...?" until I select "No".

Can't figure out why the complete queationnaire from the top is not invoked.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9446
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Repeat function not working.

Post by richmond62 » Thu Mar 23, 2023 1:26 pm

As your question is inside the repeat loop I am not sure why you are
surprised it repeats.

CAsba
Posts: 384
Joined: Fri Sep 30, 2022 12:11 pm

Re: Repeat function not working.

Post by CAsba » Thu Mar 23, 2023 1:57 pm

Hi Richmond62,
Many thanks for your reply. I thought that the status of the field cmsdone would have to be decided before the end of the repeat block, and the repeating of the code would start where the repeat instruction is placed, that is at the top; but the bit that is repeating is the question, near the bottom of the block. I tried putting the question outside the block, under it, as your answer implied, but I got a hang-up.
I'm still at a loss...

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

Re: Repeat function not working.

Post by dunbarx » Thu Mar 23, 2023 2:06 pm

CAsba

What Richmond said.

Here is something you must learn to do, step through your handlers in the debugger.

You see that when the user selects "Yes", the problem arises, whereas when "No" is selected, all is well. Place a breakPoint at the bottomMost "Answer..." line, which should seem to you to be the right place to start your investigation. Step through the handler from that point, and select "Yes".

See?

Craig

CAsba
Posts: 384
Joined: Fri Sep 30, 2022 12:11 pm

Re: Repeat function not working.

Post by CAsba » Thu Mar 23, 2023 4:43 pm

Thanks for that.
Gottit !

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”