判断数值大小及提示字符串问题 [已解决]
本帖最后由 hillgx 于 2010-9-6 17:21 编辑今天改这串代码的时候出了点问题
就是想让它 计算 1-2 = -1 (结果为负数)的时候,在 input2 里边显示字符串 “计算错误”
我试着写成这样,就出错了,结果不管算什么都是一直提示“计算错误”
If $input2 > 0 then
GUICtrlSetData($Input2,"计算错误")
EndIf
p.这代码是16进制减法计算的,不是普通的减法#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#include <String.au3>
#Region ### START Koda GUI section ### Form=
$Form2 = GUICreate("TEST", 365, 98)
$PageControl1 = GUICtrlCreateTab(8, 8, 348, 82)
$TabSheet1 = GUICtrlCreateTabItem("TabSheet1")
$Input1 = GUICtrlCreateInput("", 24, 48, 89, 22)
GUICtrlSetLimit(-1, 8)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlSetData(-1, "")
$Combo1 = GUICtrlCreateCombo("3", 136, 48, 97, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "4|5")
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
$Input2 = GUICtrlCreateInput("", 248, 48, 89, 22,$ES_READONLY)
GUICtrlSetFont(-1, 8, 400, 0, "Arial")
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Combo1
calc()
EndSwitch
WEnd
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local $hCtrl = $lParam
Switch $nID
Case $Input1
Switch $nNotifyCode
Case $EN_CHANGE
calc()
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func calc()
$var10_1 = Dec(GUICtrlRead($Input1))
$var10_2 = Dec(GUICtrlRead($Combo1))
GUICtrlSetData($Input2, Tototo($var10_1 - $var10_2))
EndFunc
Func Tototo($int)
Dim $a, $jz = 16, $aa = "", $i = 0
While 1
If $int < $jz And $int = 0 Then ExitLoop
$i = $i + 1
$a[$i] = Mod($int, $jz)
$aa = re($a[$i]) & $aa
$int = Int($int / $jz)
WEnd
Return $aa
EndFunc
Func re($x)
Select
Case $x = 0
$y = "0"
Case $x = 1
$y = "1"
Case $x = 2
$y = "2"
Case $x = 3
$y = "3"
Case $x = 4
$y = "4"
Case $x = 5
$y = "5"
Case $x = 6
$y = "6"
Case $x = 7
$y = "7"
Case $x = 8
$y = "8"
Case $x = 9
$y = "9"
Case $x = 10
$y = "A"
Case $x = 11
$y = "B"
Case $x = 12
$y = "C"
Case $x = 13
$y = "D"
Case $x = 14
$y = "E"
Case $x = 15
$y = "F"
Case Else
$y = "(" & $x & ")"
EndSelect
Return $y
EndFunc 回复 1# hillgx
$input2 是控件句柄,不是控件中的数值
If GUICtrlRead($input2) > 0 then
GUICtrlSetData($Input2,"计算错误")
EndIf 回复 2# C.L
还是不正常。
回复 3# hillgx
If GUICtrlRead($input2) > 0 then
结果大于0,输出“计算错误”。
莫非你是想结果小于0时输出? 本帖最后由 hillgx 于 2010-9-5 00:05 编辑
回复 4# 3mile
对的,小于0,结果为负的时候,再出现“计算错误” 大哥,变通一下嘛
If GUICtrlRead($input2) < 0 then
GUICtrlSetData($Input2,"计算错误")
EndIf 学习了,很好...谢谢共享
页:
[1]