Jump to content
Sign in to follow this  
John117

$Variable for '+' or "-" and still do math? possible?

Recommended Posts

Can this be done? -please dont ask what I am trying to do here. This is a reproducer intended to only prove a concept critical to my actual code. I am trying to get rid of 4 large functions where the only difference is a '+' or '-'

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
HotKeySet("{ESC}", "_Custom_Exit")
HotKeySet("{LEFT}", "_left")
HotKeySet("{RIGHT}", "_right")
$gui = GUICreate("",@DesktopWidth,40,"", "", $WS_POPUPWINDOW)
GUISetState(@SW_SHOW, $gui)

; ============================================================================
; Main Loop
; ============================================================================
While 1
    sleep(10)
WEnd
; ============================================================================
; Functions
; ============================================================================
Func _right()
    Global $sign = '+'
    _Example()
EndFunc

Func _Left()
    Global $ign = '-'
    _Example()
EndFunc

Func _Example()
MsgBox(0, "Example = 9",  4 + 5)
MsgBox(0, "Example = -1",  4 - 5)
MsgBox(0, "Example = Right or left sign option",  4 $sign 5)

EndFunc
; ============================================================================
; Functions
; ============================================================================
func _Custom_Exit()
    Exit
EndFunc ;==> _exit()
Edited by Hatcheda

Share this post


Link to post
Share on other sites

MsgBox(0, "Example = Right or left sign option", Execute("4" & $sign & "5"))

- or -

MsgBox(0, "Example = Right or left sign option", Execute(String(4 & $sign & 5)))

Edited by weaponx

Share this post


Link to post
Share on other sites

MsgBox(0, "Example = Right or left sign option", Execute("4" & $sign & "5"))

- or -

MsgBox(0, "Example = Right or left sign option", Execute(String(4 & $sign & 5)))

Perfect! :)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...