QB64.org Forum

QB64 Team Software => InForm-based programs => Topic started by: TerryRitchie on August 29, 2018, 11:48:46 pm

Title: InForm Calculator
Post by: TerryRitchie on August 29, 2018, 11:48:46 pm
I had fun learning to use InForm. Here is the calculator program I have been working on the past few days. There are still a few bugs in it (calculation errors due to QB64 giving results ending in .00000000000001 and some values coming up in scientific notation) and the Copy/Paste features are not operative. I still need to figure out how to get InForm to recognize when CTRL is pressed along with a keystroke when not on an active control.

Anyway, this little program gave me the general feel for InForm and got me back into programming QB64, a win-win.

Title: Re: InForm Calculator
Post by: FellippeHeitor on August 30, 2018, 12:05:17 am
That's really cool, Terry! I love the attention to detail with the history label!

BTW, because you're reading the keyboard with INKEY$, __UI_CtrlIsDown will return -1 but you won't read "v" or "V" or "c" or "C", but instead CHR$(22) for CTRL+V and CHR$(3) for CTRL+C, as in DOS days:

Code: QB64: [Select]
  1.             CASE CHR$(3) '                                             CTRL-C copy
  2.                 BEEP
  3.  
  4.             CASE CHR$(22) '                                             CTRL-V paste
  5.                 BEEP

That'll work.
Title: Re: InForm Calculator
Post by: TerryRitchie on August 30, 2018, 01:00:49 am
Cool, I'll incorporate that. Thanks :)
Title: Re: InForm Calculator
Post by: TempodiBasic on August 30, 2018, 07:27:37 am
Hi Terry
very cool
It brings me back in the windows  before this horrible w10.

Playing with your calculator I fall in this glitch (or feature?)
the first time that you make a SquareRoot I get in label operation (SQRT()) in an upper line  more result of  operation in a bottom line... this output stays during other operations while the line at bottom shows result of operations, if you use C then the squareroot in the upper line go away.

How to get this:
as first operation to do in calculator 1.0, or after another kind of operations if you
make 11*11 then press = and then SQR you get   SQRT(121)
                                                                                            11
or
write 144 and press SQR    you get   SQRT(144)
                                                                       12
I attach screenshot image.
Thanks for your Calculator
now I go to read code to enjoy of your comments


Title: Re: InForm Calculator
Post by: TerryRitchie on August 30, 2018, 12:02:03 pm
Yes, that's how it works. I mimicked the history line exactly as the Windows 7 calculator performs it, so the results you are seeing are correct.
Title: Re: InForm Calculator
Post by: jack on August 31, 2018, 10:33:49 am
my system is macOS High Sierra
I installed QB64 development version, it installed without complaints
I installed InForm beta 7 without complaints, however your Calculator fails to compile with the error

Quote
In file included from qbx.cpp:2179:
./../temp/main.txt:29110:33: error: use of undeclared identifier 'PlaySound'
*_SUB_ALERT_SINGLE_S=(  float  )PlaySound((char*)(qbs_add(qbs_new_txt_len("SystemDefault",13),func_chr( 0 )))->chr,NULL, 65537 );

if I comment-out where PlaySound is used, then I get the following error
Quote
ld: can't open output file for writing: ../../Calculator, errno=21 for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Title: Re: InForm Calculator
Post by: johnno56 on August 31, 2018, 10:45:30 am
I had the same error.

Check out the "Inform" forum; "Library not found"; Page #1; Comment #12 (https://www.qb64.org/forum/index.php?topic=511.0)

Something to do with a windows api being called. I run with Linux and you with Mac. Who would have thought?...

Fellippe solved that issue... Let us know how you went?

J
Title: Re: InForm Calculator
Post by: jack on August 31, 2018, 11:10:06 am
after following the suggestions by FellippeHeitor https://www.qb64.org/forum/index.php?topic=511.msg3615#msg3615 and https://www.qb64.org/forum/index.php?topic=511.msg3634#msg3634 I still get compile error 21
Title: Re: InForm Calculator
Post by: FellippeHeitor on August 31, 2018, 11:11:42 am
You say QB64 is working fine; does compiling other programs work without issue?
Title: Re: InForm Calculator
Post by: TempodiBasic on August 31, 2018, 11:20:42 am
Hi Terry
very cool Calculator 1.0 a clone of Window calculator (Calc.exe)

sorry for my bad communication...

if the behaviour of Calc.exe of Windows 10 is like that of Windows 7 then there is a different behaviour of your beautyful Calculator 1.0 vs Windows calc.exe

in the issue,
if in calculator 1.0 I type 144 ->sqrt I get SQRT(144) 12  and this is ok
 now
            if I type 9 -->SQRT I get SQRT(144) 3   
                so I get no SQRT(9) and more when I type 9  the "SQRT(144)" stays still on display and also this is different from Windows' calc.exe
            if I type 9 +1 =  I get SQRT(144) 10
                so Calculator 1.0 has in memory still previous operation flag

Thanks to read
Good Coding
Title: Re: InForm Calculator
Post by: TerryRitchie on August 31, 2018, 12:13:38 pm
I'll need to look into that. I cobbled the program together pretty quickly as mainly an exercise to learn InForm. There are bound to be bugs here and there.
Title: Re: InForm Calculator
Post by: jack on August 31, 2018, 12:29:42 pm
does compiling other programs work without issue?
I compiled and run 3dballs without problems, have not tried others.
Title: Re: InForm Calculator
Post by: jack on August 31, 2018, 12:38:26 pm
solved:
had to change
Code: QB64: [Select]
  1. '$INCLUDE:'Calculator.frm'
  2.  
to
Code: QB64: [Select]
  1. '$INCLUDE:'Calculator/Calculator.frm'
  2.  
Title: Re: InForm Calculator
Post by: jack on August 31, 2018, 12:42:34 pm
@TerryRitchie
the Return key works as the = button but the Enter key is ignored, I suggest that the Enter key also work as the = button. :)
Title: Re: InForm Calculator
Post by: jack on August 31, 2018, 01:16:04 pm
not Solved:
if after compile failure I Quit QB64 IDE and then relaunch, I get the popup "Recover program from auto-saved backup?"
I choose yes, QB64 then presents me with the calculator source, however it's titled as Untitled.
the IDE then tells me that Calculator.frm is not found, then if I change it to Calculator/Calculator.frm it then compiles the and runs the program OK
but only if I leave the name as Untitled.bas
just now QB64 crashed on me when I right-clicked on some highlighted text, trying to relaunch several times failed.
Title: Re: InForm Calculator
Post by: jack on August 31, 2018, 01:34:11 pm
strange
if I rename "Calculator.bas" to "Calculator2.bas" (anything other than Calculator.bas), then it compiles and run ok
Title: Re: InForm Calculator
Post by: jack on August 31, 2018, 03:47:00 pm
for completeness; the problem seems to be that QB64 does not want to create an application with the same name as a folder,
I had placed the Calculator folder in the qb64 folder and it seems qb64 likes to place the executables in that same folder also.
Title: Re: InForm Calculator
Post by: FellippeHeitor on August 31, 2018, 03:53:42 pm
Check "Output binary to source folder" in the run menu and you're good to go.
Title: Re: InForm Calculator
Post by: jack on August 31, 2018, 06:02:46 pm
thank you FellippeHeitor :)
Title: Re: InForm Calculator
Post by: TerryRitchie on September 16, 2018, 11:48:23 am
Just a quick note, it does have a few bugs that I have yet to correct. So don't rely on it for your rocket trajectory calculations just yet.  Elementary school pre-algebra, no sweat.
Title: Re: InForm Calculator
Post by: jack on September 18, 2018, 09:01:16 am
see this post https://www.qb64.org/forum/index.php?topic=511.msg3634#msg3634
Title: Re: InForm Calculator
Post by: FellippeHeitor on September 18, 2018, 09:06:53 am
Jack beat me to it. I already had the same link on my clipboard.

@anon1 That'll solve your issue and also answer your question about checking the os being used to compile ($IF WIN THEN: http://www.qb64.org/wiki/$IF (http://www.qb64.org/wiki/$IF)).