你的
$Day
,
$Week
$Month
是
地方的
变量(无法从全局范围访问)。更重要的是:您正在尝试设置收音机控件的文本
之前
您已经声明或初始化了这些变量。
那么你怎么解决这个问题呢?您(至少)有三种选择:
选项1
从函数中更改局部变量
Example1()
到全局范围。
-
因此,改变:
Local $Day, $Week, $Month
到
Global $Day, $Week, $Month
,
-
把它放进去
在顶部
然后
-
调用函数
示例1()
之前
您创建了GUI!
这可能是最简单但最肮脏的方法,因为任何函数都可以随时更改变量的数据。一般来说,如果可能的话,尽量不要使用全局变量。
选项2
将无线电控件更改为全局变量,然后在
作用这样地:
$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)
请注意,您必须删除未声明的变量!然后更改控件中的文本
函数使用:
GUICtrlSetData($Radio1, $Day)
GUICtrlSetData($Radio2, $Month)
GUICtrlSetData($Radio3, $Week)
选项3a
这是最安全的方法。允许
示例1()
返回变量
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
选项3b
您也可以返回值
传地址
:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $Day, $Week, $Month ; we have to declare the variables for our Example1() function BEFORE we use them
Example1($Day, $Week, $Month) ; we here call our function with the previously declared variables as parameter.
; The function will then fill in the data into our variables before we use them to set the radio text
GUICreate("Example", 143, 103, 192, 124)
GUISetFont(12, 400, 0, "Open Sans")
$Radio1 = GUICtrlCreateRadio($Day, 24, 16, 113, 17) ; set the data for the three controls
$Radio2 = GUICtrlCreateRadio($Week, 24, 40, 113, 17)
$Radio3 = GUICtrlCreateRadio($Month, 24, 64, 113, 17)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func Example1(ByRef $Day, ByRef $Week, ByRef $Month) ; NOTE: ByRef means that the given variables will be OVERWRITTEN, that also means that the variables MUST EXIST before the function is called
$LimitTime = _DateDiff('s', "1970/01/01 00:00:00", _NowCalc()) ; Get the current time (convert to seconds)
$Day = 86400
$Week = 604800
$Month = 2592000
EndFunc
来源