levanduyet Posted June 11, 2010 Share Posted June 11, 2010 I am new in AutoIt. Anyone help me to understand that How can I write the UDF to return an array. Something like following: expandcollapse popupFunc _ChoseDate() Local $n1,$n2, $msg, $button_1 Local $arrTest[2] GUICreate("Get the movements", 140, 140, 800, 200) $n1 = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_SHORTDATEFORMAT) $n2=GUICtrlCreateDate("",20,60,100,20,$DTS_SHORTDATEFORMAT) ; to select a specific default format ;$DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW ;$style = "yyyy/MM/dd HH:mm:ss" ;GUICtrlSendMsg($n1, $DTM_SETFORMAT_, 0, $style) ;GUICtrlSendMsg($n2, $DTM_SETFORMAT_, 0, $style) ; Create the controls $button_1 = GUICtrlCreateButton("&OK", 20, 100, 100, 30) GUISetState() ; In this message loop we use variables to keep track of changes to the radios, another ; way would be to use GUICtrlRead() at the end to read in the state of each control While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ;This function will return 0 if the user does not want to run this Return 0 GUIDelete() Exit Case $msg = $button_1 ;Return the chosen date $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW $style = "yyyy/MM/dd HH:mm:ss" GUICtrlSendMsg($n1, $DTM_SETFORMAT_, 0, $style) GUICtrlSendMsg($n2, $DTM_SETFORMAT_, 0, $style) $iDateCalc = _DateDiff( 'D',GUICtrlRead($n1),GUICtrlRead($n2)) if $iDateCalc<0 Then return 0 GUIDelete() Exit Else $arrTest[0]=GUICtrlRead($n1) $arrTest[1]=GUICtrlRead($n2) Return $arrTest GUIDelete() Exit EndIf EndSelect WEnd EndFunc Tks, LVD Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 11, 2010 Moderators Share Posted June 11, 2010 (edited) How about you explain in a lot more detail.Your example shows an array being returned.Edit:Unless you mean literally how to, and you're not understanding how that UDF does it?#include <Array.au3>; Used only to use _ArrayDisplay Global $a_var = _MyFunc() _ArrayDisplay($a_var) Func _MyFunc() Local $a_array[2] = ["element 0", "element 1"] Return $a_array; where $a_array is your array variable EndFuncEdit:Edited the edit Edited June 11, 2010 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 11, 2010 Share Posted June 11, 2010 (edited) I am new in AutoIt. Anyone help me to understand that How can I write the UDF to return an array. Something like following: How do you know it's not returning an array? A common mistake is to check by just trying to display the array in MsgBox() or ConsoleWrite(), which doesn't work. You can get a boolean test with IsArray(), or look at it with _ArrayDisplay() (see help file). Edit: This works fine, and the only change to your function is correcting your spelling of "Choose": expandcollapse popup#include <GuiConstantsEx.au3> #include <Date.au3> #include <DateTimeConstants.au3> #include <Array.au3> $aRET = _ChooseDate() If IsArray($aRET) Then _ArrayDisplay($aRET, "$aRET") Else MsgBox(16, "Error", "Did not return array:" & @CRLF & _ "$aRET = " & $aRET & "; Type = " & VarGetType($aRET)) EndIf Func _ChooseDate() Local $n1, $n2, $msg, $button_1 Local $arrTest[2] GUICreate("Get the movements", 140, 140, 800, 200) $n1 = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_SHORTDATEFORMAT) $n2 = GUICtrlCreateDate("", 20, 60, 100, 20, $DTS_SHORTDATEFORMAT) ; to select a specific default format ;$DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW ;$style = "yyyy/MM/dd HH:mm:ss" ;GUICtrlSendMsg($n1, $DTM_SETFORMAT_, 0, $style) ;GUICtrlSendMsg($n2, $DTM_SETFORMAT_, 0, $style) ; Create the controls $button_1 = GUICtrlCreateButton("&OK", 20, 100, 100, 30) GUISetState() ; In this message loop we use variables to keep track of changes to the radios, another ; way would be to use GUICtrlRead() at the end to read in the state of each control While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ;This function will return 0 if the user does not want to run this Return 0 GUIDelete() Exit Case $msg = $button_1 ;Return the chosen date $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW $style = "yyyy/MM/dd HH:mm:ss" GUICtrlSendMsg($n1, $DTM_SETFORMAT_, 0, $style) GUICtrlSendMsg($n2, $DTM_SETFORMAT_, 0, $style) $iDateCalc = _DateDiff('D', GUICtrlRead($n1), GUICtrlRead($n2)) If $iDateCalc < 0 Then Return 0 GUIDelete() Exit Else $arrTest[0] = GUICtrlRead($n1) $arrTest[1] = GUICtrlRead($n2) Return $arrTest GUIDelete() Exit EndIf EndSelect WEnd EndFunc ;==>_ChooseDate Edited June 11, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
levanduyet Posted June 12, 2010 Author Share Posted June 12, 2010 (edited) How do you know it's not returning an array? A common mistake is to check by just trying to display the array in MsgBox() or ConsoleWrite(), which doesn't work. You can get a boolean test with IsArray(), or look at it with _ArrayDisplay() (see help file). Edit: This works fine, and the only change to your function is correcting your spelling of "Choose": expandcollapse popup#include <GuiConstantsEx.au3> #include <Date.au3> #include <DateTimeConstants.au3> #include <Array.au3> $aRET = _ChooseDate() If IsArray($aRET) Then _ArrayDisplay($aRET, "$aRET") Else MsgBox(16, "Error", "Did not return array:" & @CRLF & _ "$aRET = " & $aRET & "; Type = " & VarGetType($aRET)) EndIf Func _ChooseDate() Local $n1, $n2, $msg, $button_1 Local $arrTest[2] GUICreate("Get the movements", 140, 140, 800, 200) $n1 = GUICtrlCreateDate("", 20, 20, 100, 20, $DTS_SHORTDATEFORMAT) $n2 = GUICtrlCreateDate("", 20, 60, 100, 20, $DTS_SHORTDATEFORMAT) ; to select a specific default format ;$DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW ;$style = "yyyy/MM/dd HH:mm:ss" ;GUICtrlSendMsg($n1, $DTM_SETFORMAT_, 0, $style) ;GUICtrlSendMsg($n2, $DTM_SETFORMAT_, 0, $style) ; Create the controls $button_1 = GUICtrlCreateButton("&OK", 20, 100, 100, 30) GUISetState() ; In this message loop we use variables to keep track of changes to the radios, another ; way would be to use GUICtrlRead() at the end to read in the state of each control While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ;This function will return 0 if the user does not want to run this Return 0 GUIDelete() Exit Case $msg = $button_1 ;Return the chosen date $DTM_SETFORMAT_ = 0x1032 ; $DTM_SETFORMATW $style = "yyyy/MM/dd HH:mm:ss" GUICtrlSendMsg($n1, $DTM_SETFORMAT_, 0, $style) GUICtrlSendMsg($n2, $DTM_SETFORMAT_, 0, $style) $iDateCalc = _DateDiff('D', GUICtrlRead($n1), GUICtrlRead($n2)) If $iDateCalc < 0 Then Return 0 GUIDelete() Exit Else $arrTest[0] = GUICtrlRead($n1) $arrTest[1] = GUICtrlRead($n2) Return $arrTest GUIDelete() Exit EndIf EndSelect WEnd EndFunc ;==>_ChooseDate Thank you. Solved. Anyway, what's wrong with my UDF above. LVD Edited June 12, 2010 by levanduyet Link to comment Share on other sites More sharing options...
PsaltyDS Posted June 12, 2010 Share Posted June 12, 2010 Anyway, what's wrong with my UDF above.??? OK, I'll be Laurel: "I don't know, Stanley, what's wrong with your UDF above?" Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now