如何将$ Day放入$ Radio1,$ Week进入$ Radio2,$ Month进入$ Radio3
并且 - $ Radio1,$ Radio2,$ Radio3进入$ RadioCheck?
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
GUICreate("Example", 143, 103, 192, 124)
GUISetFont(12, 400, 0, "Open Sans")
$Radio1 = GUICtrlCreateRadio($Day, 24, 16, 113, 17)
$Radio2 = GUICtrlCreateRadio($Week, 24, 40, 113, 17)
$Radio3 = GUICtrlCreateRadio($Month, 24, 64, 113, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Local $RadioCheck = $Radio1,$Radio2,$Radio3 ; The problem is here
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func Example1()
Local $Day, $Week, $Month
$LimitTime = _DateDiff('s', "1970/01/01 00:00:00", _NowCalc()) ;Get the current time (convert to seconds)
$Day = 86400 ; total seconds a Day
$Week = 604800 ; total seconds a Week
$Month = 2592000 ; total seconds a Month
_Example2($Example3, $Example4, $Example5-$RadioCheck)
EndFunc
答案 0 :(得分:0)
您的Any Part of Field
,$Day
和$Week
是本地变量(无法从全局范围访问)。更重要的是:您正在尝试在声明或初始化这些变量之前设置无线电控件的文本。
那么你如何解决这个问题呢?你有(至少)三个选择:
将您的局部变量从函数$Month
更改为全局范围。
Example1()
改为Local $Day, $Week, $Month
,Global $Day, $Week, $Month
!这可能是最简单但最脏的方式,因为任何函数都可以随时更改变量的数据。一般情况下尽量不要使用全局变量。
将您的无线电控件更改为全局变量,然后在Example1()
功能中更改其文本。像这样:
Example1()
到
$Radio1 = GUICtrlCreateRadio($Day, 24, 16, 113, 17)
$Radio2 = ...
请注意,您必须删除未声明的变量!然后使用以下命令更改Global $Radio1 = GUICtrlCreateRadio("", 24, 16, 113, 17)
Global $Radio2 = GUICtrlCreateRadio("", 24, 40, 113, 17)
Global $Radio3 = GUICtrlCreateRadio("", 24, 64, 113, 17)
函数中控件的文本:
Example1()
这是最安全的方式。让GUICtrlSetData($Radio1, $Day)
GUICtrlSetData($Radio2, $Month)
GUICtrlSetData($Radio3, $Week)
返回变量Example1()
,或者创建并返回一个数组。作为数组(未经测试):
ByRef
您还可以返回值#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; We are now going to receive the return values (in this case an array) from our function:
Local $aDate = Example1() ; it is essential to call this function before we want to make use of $Date[0] to $Date[2].
; What happens is that the function (code block further down) named Example1() is being executed.
; This function will then RETURN us the array.
; Since Example1() returns an array, $aData will automatically become an array filled with the data of Example1()
#Region ### START Koda GUI section ### Form=
GUICreate("Example", 143, 103, 192, 124)
GUISetFont(12, 400, 0, "Open Sans")
$Radio1 = GUICtrlCreateRadio($aDate[0], 24, 16, 113, 17) ; we are now setting the data for the three controls returned by Example1()
$Radio2 = GUICtrlCreateRadio($aDate[1], 24, 40, 113, 17)
$Radio3 = GUICtrlCreateRadio($aDate[2], 24, 64, 113, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
; Local $RadioCheck = $Radio1,$Radio2,$Radio3 ; The problem is here ---- You do not need that and PLEASE READ THE ABOUT LOCAL AND GLOBAL VARIABLES!
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func Example1()
Local $aReturn[3] ;create a (Local) Array
$LimitTime =_DateDiff('s', "1970/01/01 00:00:00", _NowCalc()) ; Get the current time (convert to seconds)
$aReturn[0] = 86400
$aReturn[1] = 604800
$aReturn[2] = 2592000
Return $aReturn ; return the Array
EndFunc
:
ByRef