Board index » delphi » error trap with infinite loop

error trap with infinite loop

Hi
I'm trying to make error traps for my program . (I don't use packed
array because I don't know how to use it). So I use strings and convert
them with my own procedures to real , word , or longinteger. Three
procedures are involved in this and I don't know where the problem is
... Can you please help??? The problem continued displaying the same
question no matter the fact that input was correct. This happened for
case 9,10 for input 22.  Thanks a lot!!!  NoViE

procedure ErrorTraps;

var  iLoop:integer;

    begin
        for iLoop:=1 to cMaxnum do
            begin
                case iLoop of
                    1: repeat
                           clrscr;
                           writeln;
                           writeln (aNumber[iLoop].question);
                           readln (aNumber[iLoop].answer)
                       until ((GetWord(aNumber[iLoop].answer) in
[1..3])) and
                       (CheckifWord(aNumber[iLoop].answer));
{and so on with cases ...............................................}
                    7: repeat
                           clrscr;
                           writeln (aNumber[iLoop].question);
                           readln (aNumber[iLoop].answer);
                       until (getreal(aNumber[iLoop].answer)

Quote
>0.00000001) and

                       (CheckifReal(aNumber[iLoop].answer)=true);
                    9,10:repeat
{and the problem is here.. Infinite loop... }
                           clrscr;
                           writeln(aNumber[iLoop].question);
                           readln(aNumber[iLoop].answer);
                         until (GetWord(aNumber[iLoop].answer)>0) and
                         (GetWord(aNumber[iLoop].answer)<40) and
                         (CheckifWord(aNumber[iLoop].answer)=true);
                end;
            end;
        writeln('press any key to continue...');
        readkey;
    end;

I'm adding the two procedures that are involved in this loop...

function GetWord(sConvert:string):word;
{converts input to a variable of type word}

var iLoop:integer;
    rTemp:word;

    begin
        rTemp:=0;
        for iLoop:=1 to 10 do
            if  (sConvert[iloop]>='0') and (sConvert[iloop]<='9') and
            (sConvert[iLoop]<>#0) then       {#0 is space}
                rTemp:=10*rTemp+ord(sConvert[iLoop])-48;
        GetWord:=rTemp;
    end;

and the next one ...
function CheckifWord(sInput:string):boolean;
{conditions that should be fulfilled for a string to be word:
true if valid to be word , false otherwise}

var  bTemp:boolean;
     iLoop,iSpaceCounter:integer;

    begin
        iSpaceCounter:=0;
        bTemp:=true;
        {check if first digit <> (number or space)}
        if (sInput[1]<'0') or (sInput[1]>'9') or (sinput[1]=#0) then
            bTemp:=false
        else
            for iLoop:=2 to 10 do
                begin
                    {counting spaces}
                    if sInput[iLoop]=#0 then
ispaceCounter:=iSpaceCounter+1;
                    {check if sinput[iloop]  <> (number or space)}
                    if ((sInput[iloop]<'0') or (sInput[iLoop]>'9')) and
                    (sInput[iloop]<>#0) then
                    begin
                        btemp:=false;
                        {end loop}
                        iLoop:=11;
                    end;
                    {check if spaces between digits}
                    if  (sInput[iloop]>='0') and (sInput[iLoop]<='9')
                    and (iSpaceCounter>0) then
                        begin
                            btemp:=false;
                            iLoop:=11;
                        end;
            end;
        {if number,is it within word range?}
        if (btemp) and ((getLongInt(sInput)>65535) or (getLongInt
(sInput)<0))
        then bTemp:=false;
        CheckifWord:=bTemp;
    end;

Sent via Deja.com
http://www.deja.com/

 

Re:error trap with infinite loop


Re:error trap with infinite loop


Post the whole program, please.
Quote
<nove...@my-deja.com> wrote in message 94rdvv$8b...@nnrp1.deja.com...
> Hi
> I'm trying to make error traps for my program . (I don't use packed
> array because I don't know how to use it). So I use strings and convert
> them with my own procedures to real , word , or longinteger. Three
> procedures are involved in this and I don't know where the problem is
> ... Can you please help??? The problem continued displaying the same
> question no matter the fact that input was correct. This happened for
> case 9,10 for input 22.  Thanks a lot!!!  NoViE

> procedure ErrorTraps;

> var  iLoop:integer;

>     begin
>         for iLoop:=1 to cMaxnum do
>             begin
>                 case iLoop of
>                     1: repeat
>                            clrscr;
>                            writeln;
>                            writeln (aNumber[iLoop].question);
>                            readln (aNumber[iLoop].answer)
>                        until ((GetWord(aNumber[iLoop].answer) in
> [1..3])) and
>                        (CheckifWord(aNumber[iLoop].answer));
> {and so on with cases ...............................................}
>                     7: repeat
>                            clrscr;
>                            writeln (aNumber[iLoop].question);
>                            readln (aNumber[iLoop].answer);
>                        until (getreal(aNumber[iLoop].answer)
> >0.00000001) and
>                        (CheckifReal(aNumber[iLoop].answer)=true);
>                     9,10:repeat
> {and the problem is here.. Infinite loop... }
>                            clrscr;
>                            writeln(aNumber[iLoop].question);
>                            readln(aNumber[iLoop].answer);
>                          until (GetWord(aNumber[iLoop].answer)>0) and
>                          (GetWord(aNumber[iLoop].answer)<40) and
>                          (CheckifWord(aNumber[iLoop].answer)=true);
>                 end;
>             end;
>         writeln('press any key to continue...');
>         readkey;
>     end;

> I'm adding the two procedures that are involved in this loop...

> function GetWord(sConvert:string):word;
> {converts input to a variable of type word}

> var iLoop:integer;
>     rTemp:word;

>     begin
>         rTemp:=0;
>         for iLoop:=1 to 10 do
>             if  (sConvert[iloop]>='0') and (sConvert[iloop]<='9') and
>             (sConvert[iLoop]<>#0) then       {#0 is space}
>                 rTemp:=10*rTemp+ord(sConvert[iLoop])-48;
>         GetWord:=rTemp;
>     end;

> and the next one ...
> function CheckifWord(sInput:string):boolean;
> {conditions that should be fulfilled for a string to be word:
> true if valid to be word , false otherwise}

> var  bTemp:boolean;
>      iLoop,iSpaceCounter:integer;

>     begin
>         iSpaceCounter:=0;
>         bTemp:=true;
>         {check if first digit <> (number or space)}
>         if (sInput[1]<'0') or (sInput[1]>'9') or (sinput[1]=#0) then
>             bTemp:=false
>         else
>             for iLoop:=2 to 10 do
>                 begin
>                     {counting spaces}
>                     if sInput[iLoop]=#0 then
> ispaceCounter:=iSpaceCounter+1;
>                     {check if sinput[iloop]  <> (number or space)}
>                     if ((sInput[iloop]<'0') or (sInput[iLoop]>'9')) and
>                     (sInput[iloop]<>#0) then
>                     begin
>                         btemp:=false;
>                         {end loop}
>                         iLoop:=11;
>                     end;
>                     {check if spaces between digits}
>                     if  (sInput[iloop]>='0') and (sInput[iLoop]<='9')
>                     and (iSpaceCounter>0) then
>                         begin
>                             btemp:=false;
>                             iLoop:=11;
>                         end;
>             end;
>         {if number,is it within word range?}
>         if (btemp) and ((getLongInt(sInput)>65535) or (getLongInt
> (sInput)<0))
>         then bTemp:=false;
>         CheckifWord:=bTemp;
>     end;

> Sent via Deja.com
> http://www.deja.com/

Other Threads