Jump to content

Recommended Posts

Posted

This is a 'simplest line calculator'... I want to get rid of the [Calc] button and have it execute() when user presses ENTER anytime.

Can anyone fix my code?

Thanks!

#NoTrayIcon
#include <GUIConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiTab.au3>

Opt("GUIOnEventMode", 1)
$wintitle = "Simplest Line Calculator"

$gui1 = GUICreate($wintitle, 160, 25, -1, -1, -1, $WS_EX_TOOLWINDOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "CloseClicked")
$inputbar = GUICtrlCreateInput("", 2, 2, 100)
$button1 = GUICtrlCreateButton("Calc", 105, 2, -1, 20, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent(-1, "DoCalc")
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd



;
Func DoCalc()
    GUICtrlSetData($inputbar, Execute(GUICtrlRead($inputbar)))
    ;_GUICtrlTab_GetCurFocus($inputbar) <-- I think this doesn't work
    ;ControlFocus($wintitle, "", "edit") <------ doesn't do it either
    Send("+{TAB}")
EndFunc
;
Func CloseClicked()
    GUIDelete()
    Exit
EndFunc
Posted

Hi,

#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Opt("GUIOnEventMode", 1)
$wintitle = "Simplest Line Calculator"

$gui1 = GUICreate($wintitle, 160, 25, -1, -1, -1, BitOr($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
$input = GUICtrlCreateInput("", 2, 2, 156)
GUISetState(@SW_SHOW)

While 1
    If Execute(GUICtrlRead($input)) And _IsPressed("0D") Then _
            GUICtrlSetData($input, Execute(GUICtrlRead($input)))
    Sleep(100)
WEnd

Func Close()
    Exit
EndFunc

Cheers

Posted

While 1

If Execute(GUICtrlRead($input)) And _IsPressed("0D") Then _

GUICtrlSetData($input, Execute(GUICtrlRead($input)))

Sleep(100)

WEnd

Ok I understand the _IsPressed() but why the execute()?

Posted

Ok I understand the _IsPressed() but why the execute()?

Perhaps smashly was checking there was something to calculate. However it's a mistake IMO because you might want to calculate something which had a result of zero and then the result wouldn't be shown.

Could have done

#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Opt("GUIOnEventMode", 1)
$wintitle = "Simplest Line Calculator"

$gui1 = GUICreate($wintitle, 160, 25, -1, -1, -1, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
$input = GUICtrlCreateInput("", 2, 2, 156)
GUISetState(@SW_SHOW)

While 1
    If _IsPressed("0D") Then
        If StringStripWS(GUICtrlRead($input), 3) <> '' Then _
                GUICtrlSetData($input, Execute(GUICtrlRead($input)))
    EndIf
    
    Sleep(100)
WEnd

Func Close()
    Exit
EndFunc  ;==>Close
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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
×
×
  • Create New...