jaywick / kalq

Tiny, simple, minimal calculator
http://jaywick.xyz/portfolio/kalq/
GNU General Public License v3.0
8 stars 3 forks source link

Unknown Result on any operation #4

Open Hanqnero opened 3 years ago

Hanqnero commented 3 years ago

The Calculator doesn't calculate anything, result always ends with "= ?". If i try to copy the result, it will copy не число (that means Not a Number).

image image

Hanqnero commented 3 years ago

Also, in the debug output there's an exception System.Runtime.InteropServices.COMException whenever the mathematical expression changes.

odinis commented 2 years ago

Having the same issue.

KarlRamstedt commented 1 year ago

Same issues here. Seems like an external dependency is causing problems.

https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.comexception?view=netframework-4.0

lrq3000 commented 10 months ago

I have been investigating a bit this bug, as I also was interested in making Kalq functional as a more mathematically complete alternative to Launchy's calculator.

I could track down the bug to this line: https://github.com/jaywick/kalq/blob/f541e05769a976fa14b1b833cdcc887923ee6f59/Classes/Calculation.vb#L43

interpreter.AddCode(script.Code)

Where interpreter is:

    ' MS Script Control object, the main engine of kalq
    Private interpreter As New MSScriptControl.ScriptControl

By looking online (it's been decades since I last coded in VB), it seems the issue stems from either a missing, corrupted, misregistered or wrong architecture (project needs to be set in 32-bits mode) msscript.ocx dll. So yes it's difficult to make it work not only in debug, but also in release, because you have to ship the correct dll and it seems it only exists in 32 bits, it's been long deprecated.

So the solution would be to replace this approach with a real math expression evaluator engine, which would also be much safer, as currently Kalq relies on executing any VBscript expression, not just math! So theoretically a nefarious actor could make you execute anything by hijacking your copy/paste (which is possible from websites!).

I had a quick look but it seems math engines are rare for VB, I found this incomplete one but it's much more verbose and complex to use: https://www.jefflewis.net/programming-vb-calculator.html#ModuleMathParser

Given all these limitations and difficulties, I decided to try alternative solutions, and for now I have settled for Qalculate (a much more mature and actively maintained math engine and GUI, much more powerful than Kalq even when it was working), combined with Clavier+ to create a hotkey to mimic how Launchy can be summoned with a simple ALT-LEFT+SPACE hotkey. So far, this approach works wonderfully well, and I get a very powerful math engine, and less memory footprint since it is launched only when I summon it (instead of having a service always running in the background as with Launchy or Kalq), so I likely won't try to fix Kalq as it is a less optimal solution in any case.