Sign in to follow this  
Followers 0
mymusicmanager

Pulling two functions at the same time

3 posts in this topic

Hello Great Internet!

So I'm attempting to create a small login program, where once the window opens, it counts down from 20. Once it hits 0, it shuts down the computer. But I still want to press the login button before the counter stops. Any ideas?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("LoginMeIN v.1.2.0", 355, 349, 192, 124)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenu("Help")
$MenuItem4 = GUICtrlCreateMenuItem("About...", $MenuItem3)
$input1 = GUICtrlCreateInput("", 120, 80, 137, 21)
$Label1 = GUICtrlCreateLabel("Username:", 64, 80, 55, 17)
$input2 = GUICtrlCreateInput("", 121, 112, 137, 21)
$Label2 = GUICtrlCreateLabel("Password:", 65, 116, 53, 17)
$Button1 = GUICtrlCreateButton("Log in", 120, 160, 137, 49)
$Button2 = GUICtrlCreateButton("Clear", 264, 144, 65, 17)
$Label3 = GUICtrlCreateLabel("Shutdown commencing in", 136, 8, 129, 17)
$Label4 = GUICtrlCreateLabel("20 seconds", 272, 8, 16, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###



Global $i = 1
for $i = 1 to 20 Step +1
    GUICtrlSetData ($label4, $i & "seconds")
    Sleep (1000)
Next




While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Button1()
        Case $button2
            Button2()
        Case $Form1
    EndSwitch
WEnd




func Button1()
    Global $read = GUICtrlRead($input1)
    Global $read2 = GUICtrlRead($input2)

    if $read == "marfro10" AND $read2 == "frotvedt" Then
        msgbox (0+16, "", "Login Successfull! Shutdown has stopped")
    Else
        MsgBox (0+16, "", "Login unsuccessfull. Please try again")
    EndIf
EndFunc

if $i = 20 Then
    msgbox (0+16, "", "Time's up!")
EndIf


Func Button2()

GUICtrlSetData ($input1, "")
GUICtrlSetData ($input2, "")

EndFunc

Share this post


Link to post
Share on other sites



mymusicmanager,

I would do something like this:

#include <GUIConstantsEx.au3>

$Form1 = GUICreate("LoginMeIN v.1.2.0", 355, 349, 192, 124)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenu("Help")
$MenuItem4 = GUICtrlCreateMenuItem("About...", $MenuItem3)
$input1 = GUICtrlCreateInput("", 120, 80, 137, 21)
$Label1 = GUICtrlCreateLabel("Username:", 64, 80, 55, 17)
$input2 = GUICtrlCreateInput("", 121, 112, 137, 21)
$Label2 = GUICtrlCreateLabel("Password:", 65, 116, 53, 17)
$Button1 = GUICtrlCreateButton("Log in", 120, 160, 137, 49)
$Button2 = GUICtrlCreateButton("Clear", 264, 144, 65, 17)
$Label3 = GUICtrlCreateLabel("Shutdown commencing in", 136, 8, 129, 17)
$Label4 = GUICtrlCreateLabel("20 seconds", 136, 25, 129, 17)
GUISetState(@SW_SHOW)

Global $i = 1
Global $iSec = @SEC

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            Button1()
        Case $Button2
            Button2()
        Case $Form1
    EndSwitch

    If @SEC <> $iSec Then
        $iSec = @SEC
        $i += 1
        GUICtrlSetData($Label4, $i & " seconds")

        If $i = 20 Then
            MsgBox(0 + 16, "", "Time's up!")
            Exit
        EndIf

    EndIf

WEnd

Func Button1()
    Global $read = GUICtrlRead($input1)
    Global $read2 = GUICtrlRead($input2)

    If $read == "marfro10" And $read2 == "frotvedt" Then
        MsgBox(0 + 16, "", "Login Successfull! Shutdown has stopped")
    Else
        MsgBox(0 + 16, "", "Login unsuccessfull. Please try again")
    EndIf
EndFunc   ;==>Button1

Func Button2()

    GUICtrlSetData($input1, "")
    GUICtrlSetData($input2, "")

EndFunc   ;==>Button2
Please ask if you have any questions. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

AutoIt can handle only one thing at once, which mean you can't pull 2 functions at the same time. You have to find a small bypass way. In Melba's way, he put the countdown and the GUI check in the same loop, so he will check 2 things after each other :)

Have fun! :)

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