找回密码
 加入
搜索
查看: 3530|回复: 6

[AU3基础] 判断数值大小及提示字符串问题 [已解决]

  [复制链接]
发表于 2010-9-4 22:18:01 | 显示全部楼层 |阅读模式
本帖最后由 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[100], $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   
发表于 2010-9-4 22:59:26 | 显示全部楼层
回复 1# hillgx
$input2 是控件句柄,不是控件中的数值
If GUICtrlRead($input2) > 0 then
        GUICtrlSetData($Input2,"计算错误")
EndIf
 楼主| 发表于 2010-9-4 23:57:08 | 显示全部楼层
回复 2# C.L

还是不正常。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2010-9-5 00:00:12 | 显示全部楼层
回复 3# hillgx
If GUICtrlRead($input2) > 0 then
结果大于0,输出“计算错误”。
莫非你是想结果小于0时输出?
 楼主| 发表于 2010-9-5 00:01:36 | 显示全部楼层
本帖最后由 hillgx 于 2010-9-5 00:05 编辑

回复 4# 3mile

对的,小于0,结果为负的时候,再出现“计算错误”
发表于 2010-9-5 00:05:43 | 显示全部楼层
大哥,变通一下嘛
If GUICtrlRead($input2) < 0 then
        GUICtrlSetData($Input2,"计算错误")
EndIf
发表于 2010-9-11 07:47:23 | 显示全部楼层
学习了,很好...  谢谢共享
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-7-5 11:53 , Processed in 0.081427 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表