Jump to content

Button click not moving to next function.


goodone
 Share

Recommended Posts

Hi, Newbie here...

I have these mixed of code from autoit forum and combined to request user to send email with their order # for order verification. It works correctly if I use only FORM2 GUI and problem arise, When I add form 2 after form 1. Most likely I am calling it wrongly. and mixed of while loop blocking me going to "congrats msg". After typing order number and clicking Ok, it should call the sendmail function and will show that congrats msg.  It only works if I delete the first while loop after Form1   and call RequestAccessCode() function directly.  

Can someone please tell me how do I correct this?

Thanks
 

#Region ### START Koda GUI section ###

$Form1 = GUICreate("Beta", 516, 220, -1, -1)
$Group4 = GUICtrlCreateGroup(" ACCESS CODE", 201, 16, 129, 81)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$REQUESTCODE = GUICtrlCreateButton("REQUEST", 216, 47, 97, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

        Case $REQUESTCODE
            RequestAccessCode()

    EndSwitch
WEnd



Func RequestAccessCode()

MsgBox($MB_SYSTEMMODAL, "Notice!", "Demo Notice")

Sleep(500)


$Form2 = GUICreate("Access Code Request Form", 251, 161, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX))
$label1 = GUICtrlCreateLabel("Inpute your order" & @CRLF & "number", 50, 20)
Global $Input1 = GUICtrlCreateInput("", 24, 96, 201, 21, $ES_NUMBER)
GUICtrlSetLimit(-1, 4)
Global $Button1 = GUICtrlCreateButton("OK", 24, 128, 75, 25)
Global $Button2 = GUICtrlCreateButton("Cancel", 152, 130, 75, 25)
GUISetState(@SW_SHOW)


EndFunc


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            If StringLen(GUICtrlRead($Input1)) < 4 Then
                GUICtrlSetData($Input1, "")
            Else
Sleep(1000)
                SendRequestEmail()
Sleep(1000)
                MsgBox($MB_SYSTEMMODAL, "", "Congrats Msg")
                Exit
            EndIf
        Case $Button2
            Exit
    EndSwitch
WEnd


Func SendRequestEmail()

$OrderNumber = GUICtrlRead($Input1)
;~ Email function

EndFunc   ;==>SendRequestEmail



 

 

Edited by goodone
Link to comment
Share on other sites

I would suggest using "on event" instead of getmsg, only one loop with everything.

Can't atm do anything with your code as im not home.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Here is your code with fixed the most obvious mistakes:

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

Global $Input1

#region ### START Koda GUI section ###

$Form1 = GUICreate("Beta", 516, 220, -1, -1)
$Group4 = GUICtrlCreateGroup(" ACCESS CODE", 201, 16, 129, 81)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$REQUESTCODE = GUICtrlCreateButton("REQUEST", 216, 47, 97, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

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

        Case $REQUESTCODE
            RequestAccessCode()

    EndSwitch
WEnd

Func RequestAccessCode()
    MsgBox($MB_SYSTEMMODAL, "Notice!", "Demo Notice")

    $Form2 = GUICreate("Access Code Request Form", 251, 161, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX))
    $label1 = GUICtrlCreateLabel("Inpute your order" & @CRLF & "number", 50, 20)
    Global $Input1 = GUICtrlCreateInput("", 24, 96, 201, 21, $ES_NUMBER)
    GUICtrlSetLimit(-1, 4)
    Global $Button1 = GUICtrlCreateButton("OK", 24, 128, 75, 25)
    Global $Button2 = GUICtrlCreateButton("Cancel", 152, 130, 75, 25)
    GUISetState(@SW_SHOW, $Form2)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button1
                If StringLen(GUICtrlRead($Input1)) < 4 Then
                    GUICtrlSetData($Input1, "")
                Else
                    SendRequestEmail()
                    MsgBox($MB_SYSTEMMODAL, "", "Congrats Msg")
                    ExitLoop
                EndIf
            Case $Button2
                ExitLoop
        EndSwitch
    WEnd

    GUISetState(@SW_HIDE, $Form2)
EndFunc   ;==>RequestAccessCode


Func SendRequestEmail()

    $OrderNumber = GUICtrlRead($Input1)
    MsgBox(0, "Email Test", $OrderNumber)
;~ Email function

EndFunc   ;==>SendRequestEmail

 

Link to comment
Share on other sites

16 hours ago, Zedna said:

Here is your code with fixed the most obvious mistakes:

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

Global $Input1

#region ### START Koda GUI section ###

$Form1 = GUICreate("Beta", 516, 220, -1, -1)
$Group4 = GUICtrlCreateGroup(" ACCESS CODE", 201, 16, 129, 81)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
$REQUESTCODE = GUICtrlCreateButton("REQUEST", 216, 47, 97, 33)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

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

        Case $REQUESTCODE
            RequestAccessCode()

    EndSwitch
WEnd

Func RequestAccessCode()
    MsgBox($MB_SYSTEMMODAL, "Notice!", "Demo Notice")

    $Form2 = GUICreate("Access Code Request Form", 251, 161, -1, -1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX))
    $label1 = GUICtrlCreateLabel("Inpute your order" & @CRLF & "number", 50, 20)
    Global $Input1 = GUICtrlCreateInput("", 24, 96, 201, 21, $ES_NUMBER)
    GUICtrlSetLimit(-1, 4)
    Global $Button1 = GUICtrlCreateButton("OK", 24, 128, 75, 25)
    Global $Button2 = GUICtrlCreateButton("Cancel", 152, 130, 75, 25)
    GUISetState(@SW_SHOW, $Form2)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $Button1
                If StringLen(GUICtrlRead($Input1)) < 4 Then
                    GUICtrlSetData($Input1, "")
                Else
                    SendRequestEmail()
                    MsgBox($MB_SYSTEMMODAL, "", "Congrats Msg")
                    ExitLoop
                EndIf
            Case $Button2
                ExitLoop
        EndSwitch
    WEnd

    GUISetState(@SW_HIDE, $Form2)
EndFunc   ;==>RequestAccessCode


Func SendRequestEmail()

    $OrderNumber = GUICtrlRead($Input1)
    MsgBox(0, "Email Test", $OrderNumber)
;~ Email function

EndFunc   ;==>SendRequestEmail

 




Thank you very much. This worked perfectly fine :)

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...