Sign in to follow this  
Followers 0
l3ill

HotKey Trouble

8 posts in this topic

Hi All,

an excellent resource ya got here...

To my question: I am not necessarily new to AutoIt but this is my first post, probably because I always found the answer I was looking for...

Up until now.

I have a Macro Set including a bunch of hot-keys that are set to automate different jobs. This part works great.

I also have a piece of code (GUI Popup box) that I would like to insert into one of these hot-key functions that by itself also seems to be working fine.

The problem is, I cant find the code needed to continue with the original hotkeyset after producing the popup box.

Basically the hotkey should:

Produce a popup and get some info (choose a destination from a drop down list)

this info should produce 2 variables; an AIM nr., and a Facility nr. ($var1 & $var2)

Open or activate a PDF file

Fill in some information

when it gets to the correct mask..

..send($var1)

send($var2)...and so on

I am including only the code I have been testing and not the entire hotkeyset so please keep that in mind if that happens to be part of the problem.

Thanks in advance for any help!!

#include <GuiConstants.au3>
#include <Excel.au3>
#include<Date.au3>

$oExcel = _ExcelBookAttach("22022010001.xlsx", "FileName");part of the original function key

;start code for popup Facility Selector
$msg = ""

$gui = GUICreate("Ship to:", 220, 120) ; will create a dialog box that when displayed is centered
$button_ok = GUICtrlCreateButton("Send", 10, 80, 100)
$button_cancel = GUICtrlCreateButton("Cancel", 110, 80, 100)
$Combo_1 = GUICtrlCreateCombo("Select", 10, 40, 200, 21)
GUICtrlSetData($Combo_1, "|Grunstadt|Stuttgart|Mainz|Italy|Schweinfurt|Illesheim|")
GUICtrlSetData(-1, "Grunstadt")
GUICtrlCreateLabel("Select Receiving Facility", 10, 10)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $button_cancel Or $msg = $GUI_EVENT_CLOSE
            Exit

        Case $msg = $button_ok
            GUICtrlRead($Combo_1)
            $Menustate = GUICtrlRead($Combo_1)
            If $Menustate = ("Grunstadt") Then $var1 = ("1342560")
            $var2 = ("7014290600")
            Exit
            If $Menustate = ("Stuttgart") Then $var1 = ("1352570")
            $var2 = ("7014290700")
            Exit
            If $Menustate = ("Mainz") Then $var1 = ("1372590")
            $var2 = ("7014290700")
            Exit
            ;and so on with the rest of the Facilities ca. 20
    EndSelect
WEnd

;end code for popup Facility Selector

;continue with rest of script
WinActivate("TLL.pdf")
WinWaitActive("TLL.pdf")
;Send("{TAB 7}") only needed for certain testing situation



    For $i = 1 To 100
    $sCellValue = _ExcelReadCell($oExcel, $i, 1)
    If $sCellValue = "" Then ExitLoop


Sleep(1500)
Send("00012")
Sleep(300)
Send("{TAB}")
Sleep(300)
Send ($var1)
Sleep(300)
Send("{TAB}")
Sleep(300)
Send ($var2)
Sleep(300)
Send("{TAB}")
Sleep(300)
Send ("1342570")
Sleep(300)
Send("{TAB}")
Sleep(300)
Send ("7014290500")
Sleep(300)
Send("{TAB 2}")
Sleep(300)
Send(_NowDate())
Sleep(300)
Send("{TAB}")


Next

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Your IF's do not look correct to me and guess you don't want to do Exit.

Something like this?

Case $msg = $button_ok
            $Menustate = GUICtrlRead($Combo_1)
            If $Menustate = "Grunstadt" Then 
                $var1 = "1342560"
                $var2 = "7014290600"
                ExitLoop
            EndIf
Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Okay,

that works great for the standalone test version but when I put in the hotkey code it leaves me with a GUI box that wont close and the only way to exit the script is to right click exit the icon in the tray.

If at all possible I would like the box to close immediately after clicking the send button.

Here is the code that works using the tip from Jos:

#include <GuiConstants.au3>
#include <Excel.au3>
#include<Date.au3>

$oExcel = _ExcelBookAttach("22022010001.xlsx", "FileName");part of the original function key

;start code for popup Facility Selector
$msg = ""

$gui = GUICreate("Ship to:", 220, 120) ; will create a dialog box that when displayed is centered
$button_ok = GUICtrlCreateButton("Send", 10, 80, 100)
$button_cancel = GUICtrlCreateButton("Cancel", 110, 80, 100)
$Combo_1 = GUICtrlCreateCombo("Select", 10, 40, 200, 21)
GUICtrlSetData($Combo_1, "|Grunstadt|Stuttgart|Mainz|Italy|Schweinfurt|Illesheim|")
GUICtrlSetData(-1, "Grunstadt")
GUICtrlCreateLabel("Select Receiving Facility", 10, 10)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $button_cancel Or $msg = $GUI_EVENT_CLOSE
            Exit

        Case $msg = $button_ok
            $Menustate = GUICtrlRead($Combo_1)
            If $Menustate = "Grunstadt" Then
                $var1 = "1342560"
                $var2 = "7014290600"
                ExitLoop
            EndIf
            If $Menustate = "Stuttgart" Then
                $var1 = "1352570"
                $var2 = "7014290700"
                ExitLoop
            EndIf
            If $Menustate = "Mainz" Then
                $var1 = "1362590"
                $var2 = "7014290900"
                ExitLoop
            EndIf
            ;and so on with the rest of the Facilities ca. 20
    EndSelect
WEnd

run( "notepad.exe","")
WinWaitActive( "Untitled" )
Sleep(2000)
Send($var1)
Sleep(2000)
Send("{ALT}")
Send("F")
Send("X")
Send("N")

And here is the hotkeyset if anybody wants to take a stab at this problem.

BTW this is my first shot at a GUI and my code probably looks very noobish to most of you :mellow:

Thanks for the help !! (the hotkey in question is F5 - lines: 249-303)

sanimacro_tester.au3

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

GuiDelete() will remove your gui so put that after you leave the While-Wend.

Don't understand the Hotkey question.

Edited by Jos

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi Again, here is the piece of code in it's basic state (changed some for testing purposes) and there are 2 problems:

  • after the popup has appeared and the choice has been made the box should close (works)
  • then the script should continue to the next step with the newly selected variables in memory (not working)
for testing I have placed a notepad open and send $var (it never gets this far though) then after all this has happened it should return to the original macro program that runs all the time, since this is only one of the hotkeys in a set (see previous post) I don't know if this will work as I haven't gotten this far yet. Thanks for all input !:mellow:

#include <GuiConstants.au3>
#include <Excel.au3>
#include<Date.au3>
#include <WindowsConstants.au3>

$oExcel = _ExcelBookAttach("22022010001.xlsx", "FileName");part of the original function key

;start code for popup Facility Selector
$msg = ""

$gui = GUICreate("Ship to:", 220, 120) ; will create a dialog box that when displayed is centered
$button_ok = GUICtrlCreateButton("Send", 10, 80, 100)
$button_cancel = GUICtrlCreateButton("Cancel", 110, 80, 100)
$Combo_1 = GUICtrlCreateCombo("Select", 10, 40, 200, 21)
GUICtrlSetData($Combo_1, "|Grunstadt|Stuttgart|Mainz|Italy|Schweinfurt|Illesheim|")
GUICtrlSetData(-1, "Grunstadt")
GUICtrlCreateLabel("Select Receiving Facility", 10, 10)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $button_cancel Or $msg = $GUI_EVENT_CLOSE
            Exit

        Case $msg = $button_ok
            GUICtrlRead($Combo_1)
            $Menustate = GUICtrlRead($Combo_1)
            If $Menustate = ("Grunstadt") Then $var1 = ("1342560")
            $var2 = ("7014290600")
            Exit
            If $Menustate = ("Stuttgart") Then $var1 = ("1352570")
            $var2 = ("7014290700")
            Exit
            If $Menustate = ("Mainz") Then $var1 = ("1372590")
            $var2 = ("7014290700")
            Exit
            ;and so on with the rest of the Facilities ca. 20
    EndSelect
WEnd

;end code for popup Facility Selector

;continue with rest of script
run( "notepad.exe","")
WinWaitActive( "Untitled" )
Sleep(2000)
Send($var1)
Send("{SPACE}")
Send($var2)
Sleep(2000)
Send("{ALT}")
Send("F")
Send("X")
Send("N")
Edited by billo

Share this post


Link to post
Share on other sites

Hey, this looks a lot like your original code with the wrong If's and Exit's in it. :mellow:

To "remember" values stored in variables set in Functions you will have to create variable with a Global scope at the beginning of your script.

Post a replication script that demo's your issue when you can't get it to work.


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Wow that is embarrassing...:(................i'm sucha noob

after 3 days of testing and pulling my hair out over this I have quite a mess of stuff here and I not only posted the old code, I have been working on the old code.

The tips you gave were right on the money and the whole thing is working now!:mellow: even the hotkey!!

For those who search and find this post with the same problem here is the working code:

And a huge thanks to Jos for your time and effort!!!

#include <GuiConstants.au3>
#include <Excel.au3>
#include<Date.au3>

$oExcel = _ExcelBookAttach("22022010001.xlsx", "FileName");part of the original function key

;start code for popup Facility Selector
$msg = ""

$gui = GUICreate("Ship to:", 220, 120) ; will create a dialog box that when displayed is centered
$button_ok = GUICtrlCreateButton("Send", 10, 80, 100)
$button_cancel = GUICtrlCreateButton("Cancel", 110, 80, 100)
$Combo_1 = GUICtrlCreateCombo("Select", 10, 40, 200, 21)
GUICtrlSetData($Combo_1, "|Grunstadt|Stuttgart|Mainz|Italy|Schweinfurt|Illesheim|")
GUICtrlSetData(-1, "Grunstadt")
GUICtrlCreateLabel("Select Receiving Facility", 10, 10)
GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $button_cancel Or $msg = $GUI_EVENT_CLOSE
            Exit

        Case $msg = $button_ok
    $Menustate = GUICtrlRead($Combo_1)
    If $Menustate = "Grunstadt" Then
    $var1 = "1342560"
    $var2 = "7014290600"
    ExitLoop
    EndIf
    If $Menustate = "Stuttgart" Then
    $var1 = "1352570"
    $var2 = "7014290700"
    ExitLoop
    EndIf
    If $Menustate = "Mainz" Then
    $var1 = "1362590"
    $var2 = "7014290900"
    ExitLoop
    EndIf
            ;and so on with the rest of the Facilities ca. 20
    EndSelect
WEnd
GuiDelete()


run( "notepad.exe","")
WinWaitActive( "Untitled" )
Sleep(2000)
Send($var1)
Send("{ENTER}")
Send($Menustate)
Sleep(2000)
Send("{ALT}")
Send("F")
Send("X")
Send("N")

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