PDA

View Full Version : proc/func from included libraries not available outside WinMain?


bobdole369
09-23-2006, 08:08 PM
Writeln() is available from the "console" library. I get the following compiler error when using outside WinMain. I think I'm missing something basic here. WriteLn() works just fine if I do everything in WinMain.

Filename : \my documents\iterate 4.ppl
Parsing...
\my documents\iterate 4.ppl
\Program Files\PPL\Lib\console.ppl
** error ** (\my documents\iterate 4.ppl) Proc or Func "WRITELN" not found at 'WRITELN' (11,1)
** error ** (\my documents\iterate 4.ppl) Proc or Func "WRITELN" not found at 'WRITELN' (13,1)
Total parsing time (411 ms)
Compiling... (3 ms)
Completion time (453 ms)
** 2 error(s), 0 warning(s)

code follows...

#include "console.ppl"
func iterate(j$)
k$=0;
while(k$<j$)
i$=0;
t$=round(tick/1000);
while((round(tick/1000))-t$<=1)
i$=i$+1;
end;
writeln(i$, "cycles");
k$=k$+1;
writeln(k$, "iterations performed");
end;
return(true);
end;


func WinMain
i$ = 0;
initConsole;
showconsole;
iterate(5);

return(true);
end;

bobdole369
09-23-2006, 08:36 PM
Improper WriteLn() usage... user error...

updated writeln lines yto:

WriteLn(i$);
Anyone know how to include text and variables in writeln?

output:
Welcome to the PPL Console

64897
1
98750
2
100146
3
100928
4
98411
5

kornalius
09-23-2006, 10:47 PM
Easy Writeln(k$ + "iterations performed");

PPL knows how to treat text and values very easily. If you want to concatenate two numbers together, try this:

k$ = 20;
Writeln(k$ + 10); // Result will be value 30
Writeln(k$ % 10); //Result will be string "2010"

The Writeln() proc requires only one parameter if I remember. It can be made to support unlimited number of parameters if needed. You will need to use nproc to declare the procedure.

bmanske
09-24-2006, 01:44 AM
If you want more control over the output, you can use a SPRINTF (pronounced S-Print-F) like in the C language to format the strings then print them. For example:
Val$ = 65536;
sprintf (Result$, "Hex Value is: %08X", Val$);
writeln(Result$); // &quot;Hex Value is: 00010000&quot; </p>

SPRINTF fills Result$ with the output shown above. It is very powerful and easy to use although arcane. Look it up in the PPL help file.
</p>