Jump to content

variable works in function but not out.


ihousden
 Share

Recommended Posts

Hi all.

Its been a long time since I used Autoit, 5 years at least. Delighted to see its still going strong.

I have what I assume will be a dumb question. My gui prompts for a username, pass, and date. This information is used to log you into a system (Resource Scheduler (RS)) and supply the date for a query. Problem is that while the gui is running, the $tdate variable works fine, but outside the function it does not. Run the code to see what im talking about. I need the variable value to cary through after the gui shuts down. MsgBox commands are placed both in and out of the function, yet return different results for $tdate.

; Includes:
#include <IE.au3>
#include <Date.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <DateTimeConstants.au3>

; Variables:
Dim $RSlogin
Dim $RSpass
Dim $tdate ; target date for query

Gui()

MsgBox(0, "Date", $tdate)   ; confirm date variable 

Exit



Func Gui()
    Local $msg, $date, $DTM_SETFORMAT_, $style
    
    GUICreate("Script Perameters", 450, 125) ; will create a dialog box that when displayed is centered
    GUISetState(@SW_SHOW) ; will display an empty dialog box
    GUICtrlCreateLabel("Enter your RS Username", 20, 20)
    $RSlogin = GUICtrlCreateInput("", 250, 15, 150, 20)
    GUICtrlCreateLabel("Enter your RS Password", 20, 40)
    $RPass = GUICtrlCreateInput("", 250, 35, 150, 20)
    GUICtrlCreateLabel("Select query target date", 20, 60)
    $tdate = GUICtrlCreateDate("", 250, 55, 100, 20)
    $btn = GUICtrlCreateButton("Ok", 195, 90, 60, 20)
    
    $DTM_SETFORMAT_ = 0x1032    ; $DTM_SETFORMATW
    $style = "MM/dd/yyyy"
    $date= GUICtrlSendMsg($tdate, $DTM_SETFORMAT_, 0, $style)
    
    GUISetState()

    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $btn
                ExitLoop
        EndSelect
    WEnd

    MsgBox(0, "Date", GUICtrlRead($tdate))  ; confirm date variable
    
    GUIDelete()
EndFunc

Im obviously not properly assigning the date input to the $tdate variable. How is that correctly done?

Thanks all.

Link to comment
Share on other sites

Link to comment
Share on other sites

In the function $tdate is a control, not a value read. Additionally you delete it at the end of the function. Define a Global $tdate_Buffer and fill it before the GUIDelete().

Thanks Kafu.

Umm, how is that done exactly? I tried adding this to the function, but it didnt work.

Global $tdate_Buffer

$tdate_Buffer = $tdate

How do I extract the control input to a value?

Thanks again.

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