Sign in to follow this  
Followers 0

Calculator Addin For Textpad

5 posts in this topic

Here is a simple scriptlet that has proven quite popular with my colleagues, which takes an arithmetic expression and returns the answer. It needs the Beta as it rdepends entirely on the new Execute() function ..

;TridsCalc.au3 - a calculator addin for text editors
;Only works with betas after 3.1.1
;Only works with betas after 3.1.1
;Only works with betas after 3.1.1
;Run options
; 1. Call this EXE 
; 2. Call this EXE with an exp[b][/b]ression in the clipboard.
; 3. Setup a tool in Textpad to call the EXE, passing the selection as an exp[b][/b]ression in the commandline
;Sample exp[b][/b]ressions
;      2 + 3 * 5
;      2+3*5
;      (2+3)*5
;      2 ^ 3
;      2 ^ 0.5 
;      1.23
;      random() * 10000
;      abs(8-23)
;      Mod(22,8)
;      Log(1000) / Log(10)
;      0x1A
;      hex(2006)

    If $CmdLineRaw = "" Then
       ;No commandline, so try the clipboard
        $sX = ClipGet()
        $sX = $CmdLineRaw
    While 1
        $sX = InputBox( @SCRIPTNAME & " - 1.1", "Exp[b][/b]ression:", $sX, "", 300,120 )
        If @ERROR Then EXITLOOP
        $asX = StringSplit( $sX, "=" )
        $sX = StringStripWS( $asX[1], 3 )
        $nX = Execute( $sX )           ;<--- this is only available in betas after 3.1.1
        $sx = $sX & " = " & $nX 

To integrate with TextPad..

  • Compile the script and save the resulting EXE to somewhere like your C:\Winnt\System32\ folder.
  • Create a TextPad tool that executes the EXE, and pass along a commandline parameter of $Sel (which TextPad replaces with the text that you have selected at runtime).
  • Assign a keyboard shortcut to the tool .. we use CTRL-/.
Now you can select a formula / expression in a TextPad document, and press your shortcut combination to evaluate it.

Have fun


Share this post

Link to post
Share on other sites

Yes, there are similarities :think: .. but I'd say the main difference is that this one is aimed at being a minimalistic addin for TextPad: no GUI stuff, except for the InputBox.

Thanks for the feedback. I must take a closer look at Au3's GUI features sometime when time allows.


Share this post

Link to post
Share on other sites

A feature I think you should have is a hotkey that will Copy whatever text you have selected and replace it with the calculated answer.

So lets say I'm in some application and I have "1+1" highlighted, have it do a Ctrl-C, ClipGet, execute it, then replace the text.

That way people could run the script.. and as they were in various documents they could highlight an equation and hit a hotkey and viola.. instant answer.

AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post

Link to post
Share on other sites

Nice idea Simucal :) .. but it might be better to leave the answer in the InputBox display. The CTrL+C and execute is cool, but pasting it back is not always possible: imagine that you select text from a browser window, for example -- you can't paste the answer back into it!

Still, the Copy-Execute is a nice idea .. give it a go :(

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0