Sign in to follow this  
Followers 0
stafe

New User - help with my first script

5 posts in this topic

I am a new user and just written my first script but I am having trouble getting it working. The aim of the script is to pull up a graphical date box where I can then select the date and on clicking okay it will insert the selected date into the underlying document.

The problem is twofold. The most important issue is that the send commands does not seem to send the contents of the variable into my underlying document. The second problem is that occasionally one click on the okay button nothing happens. I would appreciate any assistance.

The code that I have written is as follows:-

***************************************************************

#include <GuiConstants.au3>

#include <Date.au3>

dim $mydate2

; GUI

GuiCreate("Select Date", 210, 90)

GuiSetIcon(@SystemDir & "\mspaint.exe", 0)

; DATE

$MyDate = GuiCtrlCreateDate("bla", 5, 60, 200, 20, $DTS_SHORTDATEFORMAT)

;Create an "OK" button

$OK_Btn = GUICtrlCreateButton("OK", 20, 21, 70, 25)

;Create a "CANCEL" button

$Cancel_Btn = GUICtrlCreateButton("Cancel", 110, 21, 70, 25)

; GUI MESSAGE LOOP

GuiSetState()

While GuiGetMsg() <> $GUI_EVENT_CLOSE

$msg = GUIGetMsg()

$MyDate2 = GUICtrlRead($myDate)

; $MyDate2 = _DateTimeFormat($MyDate2,2)

Select

;Check if user clicked on the "OK" button

Case $msg = $OK_Btn

ClipPut($myDate2)

WinClose("Select Date")

Send($myDate2)

ExitLoop

;Check if user clicked on the "CANCEL" button

Case $msg = $Cancel_Btn

ExitLoop

EndSelect

WEnd

************************************************************************************

Thanks for any help

Stafe

Share this post


Link to post
Share on other sites



Try this:

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

Global $mydate2
GUICreate("Select Date", 210, 90)
GUISetIcon(@SystemDir & "\mspaint.exe", 0)
$MyDate = GUICtrlCreateDate("bla", 5, 60, 200, 20, $DTS_SHORTDATEFORMAT)
$OK_Btn = GUICtrlCreateButton("OK", 20, 21, 70, 25)
$Cancel_Btn = GUICtrlCreateButton("Cancel", 110, 21, 70, 25)

GUISetState()
While 1
    $msg = GUIGetMsg()
    $mydate2 = GUICtrlRead($MyDate)
    ; $MyDate2 = _DateTimeFormat($MyDate2,2)
    Select
        Case $msg = $OK_Btn
            GUISetState (@SW_MINIMIZE)
            ExitLoop
        Case $msg = $Cancel_Btn Or $msg = $GUI_Event_Close
            ExitLoop
    EndSelect
WEnd
Send($mydate2)
Exit

Share this post


Link to post
Share on other sites

Thank you Bert

That works

many thanks

One further enhancement that I am looking to do with it is that if the enter key is pressed it executes as though the OK key is pressed and if the escape key is pressed it executes as though the cancel key is pressed. If possible could you please advise me.

Stafe

Share this post


Link to post
Share on other sites

Thank you Bert

That works

many thanks

One further enhancement that I am looking to do with it is that if the enter key is pressed it executes as though the OK key is pressed and if the escape key is pressed it executes as though the cancel key is pressed. If possible could you please advise me.

Stafe

Change:

Case $msg = $OK_Btn

to

Case $msg = $OK_Btn or _IsPressed ("0D")

:whistle: Simple!

Share this post


Link to post
Share on other sites

Change:

Case $msg = $OK_Btn

to

Case $msg = $OK_Btn or _IsPressed ("0D")

:whistle: Simple!

Thanks again - you have been a great help

stafe

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