我尝试制作一个简单的自动脚本,但是我遇到了无线电切换问题无法正常工作且无法检测整数的问题。
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Local $InputListItems[3] = ["item 1", "item 2", "item 3"]
Local $test[1] = ["dog"]
Local $test1[1] = ["cat"]
$Form1 = GUICreate("Form1", 651, 250, 192, 124)
$InputMain = GUICtrlCreateGroup("Input Main", 8, 0, 137, 137)
$InputListMain = GUICtrlCreateList("", 16, 16, 121, 118)
GUICtrlSetData($InputListMain, _ArrayToString($InputListItems))
$InputAlt = GUICtrlCreateGroup("Input Alt", 151, 0, 137, 137)
$InputListAlt = GUICtrlCreateList("", 159, 16, 121, 118)
GUICtrlSetData($InputListAlt, _ArrayToString($InputListItems))
$Rates = GUICtrlCreateGroup("Rates", 6, 139, 281, 49)
$MainRateInput = GUICtrlCreateInput("1", 14, 155, 121, 21)
$AltRateInput = GUICtrlCreateInput("3", 158, 155, 121, 21)
$LeftOutputs = GUICtrlCreateGroup("Left Option", 296, 0, 169, 185)
$LeftOutputList = GUICtrlCreateList("", 304, 16, 153, 162)
GUICtrlSetData($LeftOutputList, _ArrayToString($test))
$RightOutputs = GUICtrlCreateGroup("Right Option", 472, 0, 169, 185)
$RightOutputList = GUICtrlCreateList("", 480, 16, 153, 162)
GUICtrlSetData($RightOutputList, _ArrayToString($test1))
$Output = GUICtrlCreateGroup("Main Output", 8, 192, 281, 49)
$OututInput = GUICtrlCreateInput("", 16, 208, 265, 21)
$Picker = GUICtrlCreateGroup("Option", 294, 192, 345, 49)
$Radio1 = GUICtrlCreateRadio("Left", 312, 216, 113, 17)
$Radio2 = GUICtrlCreateRadio("Right", 488, 216, 113, 17)
GUISetState(@SW_SHOW)
;GUICtrlSetState($Radio1, $GUI_CHECKED)
Func GenerateRates($MainRate, $AltRate)
Local $Start = $MainRate
Local $End = $AltRate
Local $PossibleValues[0] = []
Local $FloatTrigger = False
Local $PossibleValue = $Start & "/" & $End
_ArrayAdd($PossibleValues, $PossibleValue)
For $i = 1 To 29
$Start = $Start
$End = $End + 0.1
;If StringInStr(".", String($End)) Then
; ConsoleWrite($Start & @CRLF)
; $End = $End * 10
; $Start = $Start * 10
;EndIf
If IsInt(Number($End)) Then ; IsInt($End) <> $End ;Mod($End, 1) = 0 ;IsInt(Number($End))
$FloatTrigger = True
$StartEx = $Start
$EndEx = $End
Else
$FloatTrigger = False
EndIf
While $FloatTrigger = True
$StartEx = $StartEx + $MainRate
$EndEx = $EndEx + $AltRate + 0.1
ConsoleWrite($StartEx & @CRLF)
ConsoleWrite($EndEx & @CRLF)
Sleep(500)
If IsInt(Number($EndEx)) Then ; IsInt($EndEx) <> $End ;Mod($EndEx, 1) = 0 ;IsInt(Number($EndEx))
$FloatTrigger = True
Else
$FloatTrigger = False
EndIf
WEnd
If $FloatTrigger = True Then
$PossibleValue = $StartEx & "/" & $EndEx
Else
$PossibleValue = $Start & "/" & $End
EndIf
_ArrayAdd($PossibleValues, $PossibleValue)
Next
_ArrayDisplay($PossibleValues, "")
EndFunc ;==>GenerateRates
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $nMsg = $Radio1 = $GUI_CHECKED
If GUICtrlRead($OututInput) <> GUICtrlRead($LeftOutputList) Then
GUICtrlSetData($OututInput, GUICtrlRead($LeftOutputList))
EndIf
Case $nMsg = $Radio2 = $GUI_CHECKED
If GUICtrlRead($OututInput) <> GUICtrlRead($RightOutputList) Then
GUICtrlSetData($OututInput, GUICtrlRead($RightOutputList))
EndIf
; Working Start
Case $nMsg = $InputListMain
GUICtrlSetData($Radio1, "Left: " & GUICtrlRead($InputListMain))
Case $nMsg = $InputListAlt
GUICtrlSetData($Radio2, "Right: " & GUICtrlRead($InputListAlt))
; Working End
Case $nMsg = $MainRateInput
If GUICtrlRead($Radio1) = 1 Then
GenerateRates(GUICtrlRead($MainRateInput), GUICtrlRead($AltRateInput))
Else
GenerateRates(GUICtrlRead($AltRateInput), GUICtrlRead($MainRateInput))
EndIf
Case $nMsg = $AltRateInput
If GUICtrlRead($Radio1) = 1 Then
GenerateRates(GUICtrlRead($MainRateInput), GUICtrlRead($AltRateInput))
Else
GenerateRates(GUICtrlRead($AltRateInput), GUICtrlRead($MainRateInput))
EndIf
EndSwitch
WEnd
IsInt(Number($value))
或Mod($value, 1) = 0
但是在我的脚本中它根本不起作用。我尝试了大量不同的写法案例,包括:Case $nMsg = GUICtrlRead($Radio1) = $GUI_CHECKED
和Case $nMsg = $Radio1 And BitAND(GUICtrlRead($Radio1), $GUI_CHECKED) = $GUI_CHECKED
我已经尝试了我所知道的所有测试值,包括:ConsoleWrite(_WinAPI_FloatToInt($End) & @CRLF)
,看看是否有帮助,但事实并非如此。它们似乎都是浮点数,即使有些数字例如显示整数(5)。
答案 0 :(得分:0)
目前,处理GUI事件的while语句存在问题,因为像
这样的语句Case $ nMsg = $ Radio1 = $ GUI_CHECKED
似乎被解释为
案例$ nMsg
因此,只会触发第一个这样的语句(因为我们必须有$ nMsg == $ nMsg)。程序成功退出的唯一原因是它的代码是switch语句中的第一个块。修复非常简单,$ Radio1的GUI代码只是$ Radio1
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Radio1
If GUICtrlRead($OututInput) <> GUICtrlRead($LeftOutputList) Then
GUICtrlSetData($OututInput, GUICtrlRead($LeftOutputList))
EndIf
Case $Radio2
If GUICtrlRead($OututInput) <> GUICtrlRead($RightOutputList) Then
GUICtrlSetData($OututInput, GUICtrlRead($RightOutputList))
EndIf
; Working Start
Case $InputListMain
GUICtrlSetData($Radio1, "Left: " & GUICtrlRead($InputListMain))
Case $InputListAlt
GUICtrlSetData($Radio2, "Right: " & GUICtrlRead($InputListAlt))
; Working End
Case $MainRateInput
If GUICtrlRead($Radio1) = 1 Then
GenerateRates(GUICtrlRead($MainRateInput), GUICtrlRead($AltRateInput))
Else
GenerateRates(GUICtrlRead($AltRateInput), GUICtrlRead($MainRateInput))
EndIf
Case $AltRateInput
If GUICtrlRead($Radio1) = 1 Then
GenerateRates(GUICtrlRead($MainRateInput), GUICtrlRead($AltRateInput))
Else
GenerateRates(GUICtrlRead($AltRateInput), GUICtrlRead($MainRateInput))
EndIf
EndSwitch
WEnd
整数测试的问题可能归结为浮点舍入。但是,正如您的代码当前编写的那样,如果将$ FloatTrigger设置为true,那么您将在无限循环中结束