Forgive me if this is a known problem I've searched but I can't find anything about it.
the following code simulates a problem that I have experienced, mainly a missing closing brace. The code is purely to demonstrate this problem
The code below has a brace remarked out, the code compiles and runs fine but the results are not as expected.
with the brace inserted a message box should be displayed giving the caption as "Error in Data", however it shows the box with the caption
,"Box Should never show!!".
I suspect it has something to do with the do{}until(), as without this, the missing brace flags a compile error.
Sub main()
{
int n;
n=Func();
return;
}
Sub Func(),int
{
int err;
err=0;
do
{
err=1;
if (err)
{
if(err=1)
{
s="Incorrect Data!";
}
else
{
s="Invalid data!";
// }
messagebox(0,s,"Error in Data",IDOK);
}
else
{
err=1;
messagebox(0,s,"Box Should never show!!",IDOK);
}
}
until(err<>0);
return err;
}
regards John
I will look into it. Basically you are throwing off the context of the compiler. With the missing brace the compiler sees this:
Sub Func(),int
{
int err;
err=0;
do
{
err=1;
if (err)
{
if(err=1)
{
s="Incorrect Data!";
}
else
{
s="Invalid data!";
// }
messagebox(0,s,"Error in Data",IDOK);
}
else
{
err=1;
messagebox(0,s,"Box Should never show!!",IDOK);
}
}
until(err<>0);
return err;
}
Which is two else's after an if. The second else pops the context stack removing the first 'if' context so it is as if it never existed in the first place, and you don't get an error.
Paul.
Thanks for a quick reply on that.
John