Jump to content

RunWait on a function?


gcue
 Share

Recommended Posts

within a for loop, i prompt for a credential login. (which is a guicreate)

if the user leaves the prompt on without logging in, the for loop continues to the next item

#include <WindowsConstants.au3>
#Include <GuiEdit.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $pc, $array[3], $credentials_child, $netsupport_login_successful = False

$array[0] = "1"
$array[1] = "2"
$array[1] = "3"

For $x = 1 to UBound($array) - 1

    $pc = $array[$x]

    If $netsupport_login_successful = False Then
        Netsupport_Prompt()
    Else
        Netsupport_Login()
    EndIf

Next

Func Netsupport_Prompt()

    If WinExists("Netsupport Buddy Login") Then
        MsgBox(262144, "Dashboard", "Already running Netsupport Buddy Login.")
        Return
    EndIf

    $credentials_child = GUICreate("Netsupport Buddy Login", 265, 90, -1, -1, $WS_EX_MDICHILD, $WS_EX_TOPMOST)

    $username_input = GUICtrlCreateInput(@UserName, 5, 5, 200, 20)
    $password_input = GUICtrlCreateInput("", 5, 30, 200, 20, $ES_PASSWORD)
    GUICtrlSetState(-1, $gui_focus)

    $OK_btn = GUICtrlCreateButton("OK", 210, 5, 40, 20)
    GUICtrlSetOnEvent(-1, "Netsupport_Login")

    $CANCEL_btn = GUICtrlCreateButton("Cancel", 210, 30, 40, 20)
    GUICtrlSetOnEvent(-1, "DEL_credentials_child")

    GUISetState()

EndFunc   ;==>Netsupport_Prompt

func DEL_credentials_child()
    exit
EndFunc

Func Netsupport_Login()
    $netsupport_login_successful = True
    MsgBox(0,"",$pc)
EndFunc   ;==>Netsupport_Login

while 1
    sleep(10)
WEnd
Edited by gcue
Link to comment
Share on other sites

And the question is?

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

Link to comment
Share on other sites

The "code" posted doesn't make sense. It won't even pass AutoIt check, and it does serve no purpose.

What is the point of setting up a GUI if you don't get anything from it?

The For loop has syntax error.

Your test is hanging in the sky.

Other function is missing.

So what?

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

sorry sometimes i try not to post too long of a code otherwise folks might not bother to read.

i have revised my script in my post ABOVE to better illustrate my point - again sorry about that.

my question is: the array goes through the first record and prompts for a password if authentication has not been provided but if the user does not enter their credentials right away, the for loop continues anyway. i want the loop to stop until the user has entered his/her credentials

so when i call the function within the loop, is there a way i can make it wait until the user has entered credentials?

i thought maybe in the way i call the function it could be done (but runwait seems to be only for EXEs or files)

or i can use a condition

if $netsupport_login_successful = true then continueloop

but what if its false?

do

sleep

until $netsupport_login_successful = True

wont that tie up the script from the user entering his credentials?

Edited by gcue
Link to comment
Share on other sites

my question is: the array goes through the first record and prompts for a password if authentication has not been provided but if the user does not enter their credentials right away, the for loop continues anyway. i want the loop to stop until the user has entered his/her credentials

That's logical. Since you don't bother to even read what the user has entered, I hardly see how you can validate anything.

You need to GUICtrlGetData from your input controls and do something to validate what has been entered, e.g. perform loging in. If you find that, say, the password has been left blank, then you should probably avoid invoking

GUICtrlSetOnEvent(-1, "Netsupport_Login")

automatically!

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

i do bother to read it.. the actual script is much longer.. but this script illustrates the process and what im trying to wait on

Your mutilated script doesn't illustrate anything as it stands.

Show where you get the user input and what you do with hat data.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

if you run this you will see what im getting at...

before the user can enter credentials into the GUI the for loop continues and another GUI tries to get created...

how can i do a Wait for Input in a for loop?

#include <WindowsConstants.au3>
#Include <GuiEdit.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $pc, $array[3], $credentials_child, $netsupport_login_successful = False

$array[0] = "1"
$array[1] = "2"
$array[2] = "3"

For $x = 0 to UBound($array) - 1

    $pc = $array[$x]

    If $netsupport_login_successful = False Then
        Netsupport_Prompt()
    Else
        Netsupport_Login()
    EndIf

Next

exit

Func Netsupport_Prompt()

    If WinExists("Netsupport Buddy Login") Then
        MsgBox(262144, "Dashboard", "Already running Netsupport Buddy Login.")
        Return
    EndIf

    $credentials_child = GUICreate("Netsupport Buddy Login", 265, 90, -1, -1, $WS_EX_MDICHILD, $WS_EX_TOPMOST)

    $username_input = GUICtrlCreateInput(@UserName, 5, 5, 200, 20)
    $password_input = GUICtrlCreateInput("", 5, 30, 200, 20, $ES_PASSWORD)
    GUICtrlSetState(-1, $gui_focus)

    $OK_btn = GUICtrlCreateButton("OK", 210, 5, 40, 20)
    GUICtrlSetOnEvent(-1, "Netsupport_Login")

    $CANCEL_btn = GUICtrlCreateButton("Cancel", 210, 30, 40, 20)
    GUICtrlSetOnEvent(-1, "DEL_credentials_child")

    GUISetState()

EndFunc   ;==>Netsupport_Prompt

func DEL_credentials_child()
    Exit
EndFunc

Func Netsupport_Login()
    $netsupport_login_successful = True
    ConsoleWrite($pc & @LF)
    GUIDelete($credentials_child)
EndFunc   ;==>Netsupport_Login

while 1
    sleep(10)
WEnd
Link to comment
Share on other sites

  • Moderators

gcue,

Just use the flag you already have as the condition for a While...WEnd loop:

Func Netsupport_Prompt()

    If WinExists("Netsupport Buddy Login") Then
        MsgBox(262144, "Dashboard", "Already running Netsupport Buddy Login.")
        Return
    EndIf

    $credentials_child = GUICreate("Netsupport Buddy Login", 265, 90, -1, -1, $WS_EX_MDICHILD, $WS_EX_TOPMOST)

    $username_input = GUICtrlCreateInput(@UserName, 5, 5, 200, 20)
    $password_input = GUICtrlCreateInput("", 5, 30, 200, 20, $ES_PASSWORD)
    GUICtrlSetState(-1, $gui_focus)

    $OK_btn = GUICtrlCreateButton("OK", 210, 5, 40, 20)
    GUICtrlSetOnEvent(-1, "Netsupport_Login")

    $CANCEL_btn = GUICtrlCreateButton("Cancel", 210, 30, 40, 20)
    GUICtrlSetOnEvent(-1, "DEL_credentials_child")

    GUISetState()

    While $netsupport_login_successful = False
        Sleep(10)
    WEnd

    ConsoleWrite("We are here because the log-in was successful" & @CRLF)

EndFunc   ;==>Netsupport_Prompt

Func Netsupport_Login()

    ; Errorcheck inputs
    If GUICtrlRead($username_input) = "" Or GUICtrlRead($password_input) = "" Then Return

    ; You only want to set this value to True IF the login was successful!!!!!
    $netsupport_login_successful = True
    ConsoleWrite($pc & @LF)
    GUIDelete($credentials_child)
EndFunc   ;==>Netsupport_Login

But as it says in the comment line, you MUST make sure your log-in is successful before you set the flag to True.

I hope this helps. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

if you run this you will see what im getting at...

before the user can enter credentials into the GUI the for loop continues and another GUI tries to get created...

how can i do a Wait for Input in a for loop?

#include <WindowsConstants.au3>
#Include <GuiEdit.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $pc, $array[3], $credentials_child, $netsupport_login_successful = False

$array[0] = "1"
$array[1] = "2"
$array[2] = "3"

For $x = 0 to UBound($array) - 1

    $pc = $array[$x]

    If $netsupport_login_successful = False Then
        Netsupport_Prompt()
    Else
        Netsupport_Login()
    EndIf

Next

exit

Func Netsupport_Prompt()

    If WinExists("Netsupport Buddy Login") Then
        MsgBox(262144, "Dashboard", "Already running Netsupport Buddy Login.")
        Return
    EndIf

    $credentials_child = GUICreate("Netsupport Buddy Login", 265, 90, -1, -1, $WS_EX_MDICHILD, $WS_EX_TOPMOST)

    $username_input = GUICtrlCreateInput(@UserName, 5, 5, 200, 20)
    $password_input = GUICtrlCreateInput("", 5, 30, 200, 20, $ES_PASSWORD)
    GUICtrlSetState(-1, $gui_focus)

    $OK_btn = GUICtrlCreateButton("OK", 210, 5, 40, 20)
    GUICtrlSetOnEvent(-1, "Netsupport_Login")

    $CANCEL_btn = GUICtrlCreateButton("Cancel", 210, 30, 40, 20)
    GUICtrlSetOnEvent(-1, "DEL_credentials_child")

    GUISetState()

EndFunc   ;==>Netsupport_Prompt

func DEL_credentials_child()
    Exit
EndFunc

Func Netsupport_Login()
    $netsupport_login_successful = True
    ConsoleWrite($pc & @LF)
    GUIDelete($credentials_child)
EndFunc   ;==>Netsupport_Login

while 1
    sleep(10)
WEnd

U could also wait for U'r gui to be closed :D

#include <WindowsConstants.au3>
#Include <GuiEdit.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $pc, $array[3], $credentials_child, $netsupport_login_successful = False

$array[0] = "1"
$array[1] = "2"
$array[2] = "3"

For $x = 0 to UBound($array) - 1

    $pc = $array[$x]

    If $netsupport_login_successful = False Then
        Netsupport_Prompt()
        WinWaitClose("Netsupport Buddy Login", "")
    Else
        Netsupport_Login()
    EndIf

Next

exit

Func Netsupport_Prompt()

    If WinExists("Netsupport Buddy Login") Then
        MsgBox(262144, "Dashboard", "Already running Netsupport Buddy Login.")
        Return
    EndIf

    $credentials_child = GUICreate("Netsupport Buddy Login", 265, 90, -1, -1, $WS_EX_MDICHILD, $WS_EX_TOPMOST)

    $username_input = GUICtrlCreateInput(@UserName, 5, 5, 200, 20)
    $password_input = GUICtrlCreateInput("", 5, 30, 200, 20, $ES_PASSWORD)
    GUICtrlSetState(-1, $gui_focus)

    $OK_btn = GUICtrlCreateButton("OK", 210, 5, 40, 20)
    GUICtrlSetOnEvent(-1, "Netsupport_Login")

    $CANCEL_btn = GUICtrlCreateButton("Cancel", 210, 30, 40, 20)
    GUICtrlSetOnEvent(-1, "DEL_credentials_child")

    GUISetState()

EndFunc   ;==>Netsupport_Prompt

func DEL_credentials_child()
    Exit
EndFunc

Func Netsupport_Login()
    $netsupport_login_successful = True
    ConsoleWrite($pc & @LF)
    GUIDelete($credentials_child)
EndFunc   ;==>Netsupport_Login

while 1
    sleep(10)
WEnd

Cheers

/Rex

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...