    'LOOP_CONTROL
    do
	if maxX < mm.hres then ' draw the limits if designing on a larger display
      box 0,0,maxX,maxY,1,RGB(YELLOW)
    endif
      printit
      txt$ = ""
      do
        k$ = inkey$
      loop until k$<>""
      redrawit = 1
      select case k$
        case "g","G" ' toggle grid
          'move = grid + 1 - move
            if move = 1 then : move = 5
            elseif move = 5 then : move = 10
          else : move = 1 : endif
          redrawit = 0
        case chr$(128) ' up
          inc cpos(ctrl,a), -move
          cpos(ctrl,a) = (cpos(ctrl,a)\move)*move
        case chr$(129) ' down
          inc cpos(ctrl,a) , move
          cpos(ctrl,a) = (cpos(ctrl,a)\move)*move
        case chr$(130) ' left
          inc cpos(ctrl,b), -move
          cpos(ctrl,b) = (cpos(ctrl,b)\move)*move
        case chr$(131) ' right
          inc cpos(ctrl,b) , move
          cpos(ctrl,b) = (cpos(ctrl,b)\move)*move
        case "+"
          inc cpos(ctrl,5), 1
          if cpos(ctrl,5)>30 then cpos(ctrl,5)=30
        case "-"
          inc cpos(ctrl,5), -1
          if cpos(ctrl,5)<1 then cpos(ctrl,5)=1
        case "z","Z"
          b = 4-b ' b = 1 or 3
          a = 6-a ' a = 2 or 4
          redrawit = 0
        case chr$(32)
          inc ctrl
          if ctrl > maxctrl then
            ctrl = 1
          endif
          ' Txt$ = "Control "+str$(ctrl)
          redrawit = 0
        case "s","S" ' save position data
          if mm.device$ = "MMBasic for Windows" then
            open "loopcontrol.bas" for output as #1
            print #1, "position_data:"
            for n = 1 to maxctrl
              print #1, "DATA "+str$(cpos(n,1))+","+str$(cpos(n,2))+","+str$(cpos(n,3))+","+str$(cpos(n,4))+","+str$(cpos(n,5))
              if cpos(n,1) = -1 then exit for
            next n
            print #1,"DATA -1, -1, -1, -1, -1"
            close #1
            txt$ = MM.INFO$(DIRECTORY)+"loopcontrol.bas"
            system txt$
          else
            print "position_data:"
            for n = 1 to maxctrl
              print "DATA "+str$(cpos(n,1))+","+str$(cpos(n,2))+","+str$(cpos(n,3))+","+str$(cpos(n,4))+","+str$(cpos(n,5))
            next n
            print "DATA -1, -1, -1, -1, -1"
			print
          endif
          redrawit = 0
      end select
      if cpos(ctrl,b) <4 and b = 3 then cpos(ctrl,b) = 4
      if cpos(ctrl,b) <0 and b = 1 then cpos(ctrl,b) = 0
      if cpos(ctrl,a) <4 and b = 3 then cpos(ctrl,a) = 4
      if cpos(ctrl,a) <0 and b = 1 then cpos(ctrl,a) = 0
	  IF cpos(ctrl,b) >maxX THEN cpos(ctrl,b) = maxX
      IF cpos(ctrl,a) >maxY THEN cpos(ctrl,a) = maxY
    loop until redrawit = 1
    gui delete all
    cls
  loop
  
sub printit
  if txt$="" then
    if b = 1 then
      txt$ = "Control "+str$(ctrl)+", Step size "+str$(move)+", X="+str$(cpos(ctrl,1))+", Y="+str$(cpos(ctrl,2))+", Txt/rnd="+str$(cpos(ctrl,5))
    else
      txt$ = "Control "+str$(ctrl)+", Step size "+str$(move)+", W="+str$(cpos(ctrl,3))+", H="+str$(cpos(ctrl,4))+", Txt/rnd="+str$(cpos(ctrl,5))
    endif
  endif
  if mm.device$ = "MMBasic for Windows" then
    text 10, mm.vres - 30, txt$+space$(40)
  else
    print chr$(27)+"[1A"+txt$+space$(40)
  endif
  txt$=""
end sub
  