Jump to content
Sign in to follow this  
gte

How to use math (operators) in a statement or function and then write them to a variable

Recommended Posts

gte

This is probably a really easy thing, but I'm not sure how to do it and I've searched and not found an answer

Every time I use the +=, my script will not build and fails at the + symbol, what is the syntax that needs to be used in?

I'm trying to do this

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiComboBox.au3>


$Form4 = GUICreate("Password Dialog", 786, 339, -1, -1)
GUISetIcon("D:\008.ico")
$schtasktimelabel = GUICtrlCreateLabel("Enter Time in HH:MM:SS", 496, 40, 123, 17)
$schtaskcreatebutton = GUICtrlCreateButton("Create the scheduled task", 608, 120, 83, 65, $BS_MULTILINE)
$schtaskdate = GUICtrlCreateDate("2009/05/05 11:06:28", 320, 72, 186, 21, $WS_TABSTOP)
$schtaskinputtime = GUICtrlCreateInput('xx:xx:xx', 520, 72, 65, 21)
$schtaskampmmenu = GUICtrlCreateCombo('', 616, 72, 81, 25);, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
_GUICtrlComboBox_SetEditText($schtaskampmmenu, "AM or PM?")
$schtaskampm = GUICtrlSetData(-1, 'AM|PM') 



GUISetState(@SW_SHOW)


While 1
    
    $nMsg = GUIGetMsg()
    
    
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $schtaskcreatebutton
                createtask()    

    EndSwitch
WEnd


    
func createtask()
        

$am = '0'
$pm = '12'

         $schtaskamorpm = guictrlread($schtaskampmmenu)
            if $schtaskamorpm = 'AM' Then
                $schtaskampmoutput = '+0'
                MsgBox(4096, "Test", " You selected AM   ", 3)
            ElseIf $schtaskamorpm = "PM" Then
                $schtaskampmoutput = '+12'
                MsgBox(4096, "Test", " You selected PM   ", 3)
            EndIf

$schtaskstarttime = guictrlread($schtaskinputtime) += ($schtaskampmoutput)



EndFunc

Except I am using (at least) the += incorrectly???

After that I have to figure out how to only have it update/add to the first set of numbers in a 10:11:12 section of a cmd file :confused:

Share this post


Link to post
Share on other sites
Xenobiologist

Hi,

you can use WM_Command to verify the input

#include<Array.au3>
#include<EditConstants.au3>
#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>

;Global $changed = False

GUICreate("My GUI Zeiteingabe",200,100) ; will create a dialog box that when displayed is centered

$edit = GUICtrlCreateInput("  :", 10, 30, 52, 20,$ES_NUMBER); Eingabebox
GUICtrlSetFont(-1,10,600,0,"Courier New"); nichtproportionale Schrift gewählt, für die Optik des gleichbleibenden Abstandes vor dem ":" mit Leerzeichen
GUICtrlSetLimit(-1,5)
$edit1 = GUICtrlCreateInput("  :", 75, 30, 52, 20,$ES_NUMBER); Eingabebox
GUICtrlSetFont(-1,10,600,0,"Courier New"); nichtproportionale Schrift gewählt, für die Optik des gleichbleibenden Abstandes vor dem ":" mit Leerzeichen
GUICtrlSetLimit(-1,5)
$edit2 = GUICtrlCreateInput("  :", 140, 30, 52, 20,$ES_NUMBER); Eingabebox
GUICtrlSetFont(-1,10,600,0,"Courier New"); nichtproportionale Schrift gewählt, für die Optik des gleichbleibenden Abstandes vor dem ":" mit Leerzeichen
GUICtrlSetLimit(-1,5)
$btn = GUICtrlCreateButton("Ohne Funktion", 50, 70, 100, 20)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
Send("{LEFT 3}")
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd

Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $backspc = 0
    Local $nNotifyCode = _HiWord($wParam)
    Local $nID = _LoWord($wParam)
    Local $hCtrl = $lParam
    Switch $nID; aktuelle Inputbox
        Case $edit Or $edit1 Or $edit2
            Switch $nNotifyCode
                Case $EN_CHANGE
                    $temp = StringSplit(GUICtrlRead($nID),":")
                    If @error Then
                        _ArrayAdd($temp,"")
                    EndIf
                    $temp[1] = StringReplace($temp[1]," ","")                       
                    If $temp[0] = 1 Then
                        $temp[1] = StringLeft($temp[1],1)&" "
                        GUICtrlSetData($nID,$temp[1]&":")
                        Send("{LEFT 2}")
                    EndIf
                    Switch StringLen($temp[2])
                        Case 2
                            Send("{TAB}")
                        Case 1
                            If NOT StringIsDigit($temp[1]) Then
                                GuiCtrlSetData($nID,"  :")
                                Send ("{LEFT 3}")
                            EndIf
                            If $temp[2] > 5 Then
                                $temp[2]=""
                                GuiCtrlSetData($nID,$temp[1]&":"&$temp[2])
                            EndIf
                        Case 0
                        Switch StringLen($temp[1])
                            Case 2
                                Switch StringLeft($temp[1],1)
                                    Case 2
                                        If $temp[1] > 23 Then
                                            $temp[1] = "2 "
                                            GuiCtrlSetData($nID,$temp[1]&":")
                                            send ("{LEFT 2}")
                                        Else 
                                            GuiCtrlSetData($nID,$temp[1]&":")
                                        EndIf                                       
                                    Case 1
                                        GuiCtrlSetData($nID,$temp[1]&":")   
                                    Case 0
                                        GuiCtrlSetData($nID,$temp[1]&":")   
                                EndSwitch
                            Case 1 
                                Switch $temp[1]
                                    Case 3 to 9
                                        $temp[1] = "0"&$temp[1]
                                        GuiCtrlSetData($nID,$temp[1]&":")
                                    Case 0 to 2
                                        GuiCtrlSetData($nID,$temp[1]&" :")
                                        send ("{LEFT 2}")
                                EndSwitch
                            Case 0
                                GuiCtrlSetData($nID,"  :")
                                send ("{LEFT 3}")
                        EndSwitch
                    EndSwitch
                Case $EN_SETFOCUS
                    GuiCtrlSetData($nID,"  :")
                    Send("{LEFT 3}")
                Case $EN_KILLFOCUS
                    $temp = StringSplit(GUICtrlRead($nID),":")
                    $temp[1] = StringReplace($temp[1]," ","")
                    If $temp[0] = 1 Then _ArrayAdd($temp,"")
                    If StringLen($temp[2]) = 2 Then 
                        If StringLen($temp[1]) = 2 Then
                            Return
                        Else
                            GUICtrlSetData($nID,"  :")
                            Return
                        EndIf
                    EndIf
                    Switch StringisDigit($temp[1])
                        Case True
                            Switch StringLen($temp[1])
                                Case 1
                                    If $temp[1] > 2 Then $temp[1] = "0"&$temp[1]
                                    If $temp[1] <= 2 Then $temp[1] = "  "
                                Case 2
                                    If $temp[2] > "" Then
                                        $temp[2] = $temp[2]&"0"
                                        GUICtrlSetData($nID,$temp[1]&":"&$temp[2])
                                    EndIf
                            EndSwitch
                            If $temp[2] = "" Or $temp[2] = 0 Then
                                $temp[2] = "00"
                                GUICtrlSetData($nID,$temp[1]&":"&$temp[2])
                            EndIf                           
                        Case False
                            GUICtrlSetData($nID,"  :")
                    EndSwitch
            EndSwitch
    EndSwitch
EndFunc  ;==>MY_WM_COMMAND

Func _HiWord($x)
    Return BitShift($x, 16)
EndFunc  ;==>_HiWord

Func _LoWord($x)
    Return BitAND($x, 0xFFFF)
EndFunc  ;==>_LoWord

and maybe you should use _DateAdd to calculate the time like this

#include <GUIConstants.au3>
#include <date.au3>

; GUI-Design by Carsten8

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Aktuelle Zeit", 300, 200, 193, 115)
GUISetBkColor(0x000000)
$Input0 = GUICtrlCreateLabel("Zeit in DE", 8, 8, 400, 30)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetBkColor(-1, 0x000000)
$Input1 = GUICtrlCreateLabel("TAG", 8, 30, 400, 30)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
$Input2 = GUICtrlCreateLabel("Stunde", 8, 53, 300, 30)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
$Input3 = GUICtrlCreateLabel("Zeit in Korea", 8, 108, 400, 30)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetBkColor(-1, 0x000000)
$Input4 = GUICtrlCreateLabel("TAG", 8, 130, 400, 30)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
$Input5 = GUICtrlCreateLabel("Stunde", 8, 153, 300, 30)
GUICtrlSetFont(-1, 14, 400, 0, "Arial")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
#EndRegion ### END Koda GUI section ###
AdlibEnable("_DateUpdate", 500)
GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Func _DateUpdate()
    $date = _NowCalc()
    GUICtrlSetData($Input2, _DateTimeFormat($date, 5))
    GUICtrlSetData($Input1, _DateTimeFormat($date, 1))
    $theirdate = _DateAdd("h", 8, $date)
    GUICtrlSetData($Input5, _DateTimeFormat($theirdate, 5))
    GUICtrlSetData($Input4, _DateTimeFormat($theirdate, 1))
EndFunc  ;==>_DateUpdate

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites
gte

I tried that, and it didn't error, I'm not sure why that was necessary, can you explain?

Also, I can only get it to add when I hard code a single integer value for $schtaskinputtime

When I have it set as guictrlread or I have the value needed for the schtask, HH:MM:SS it excludes it and just displays the value of $schtaskinputtime

???

Try:

$schtaskstarttime = guictrlread($schtaskinputtime) + $schtaskampmoutput ;)

You allready have a = ^_^

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.