[已解決] 修改$A1的數字為千分位+逗點
本帖最后由 tcpuuu 于 2012-2-22 15:46 编辑GUICreate('千分位+逗點',200,180,1,1)
$a1 = GUICtrlCreateInput("7200", 10, 10, 80, 22,0x01)
GUICtrlSetFont($input,12)
GUICtrlSetData($A1,千分位+逗點);修改$A1的數字為千分位+逗點
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd===================================================
這段該如何敘述?
GUICtrlSetData($A1,千分位+逗點);修改$A1的數字為千分位+逗點 GUICreate('千分位+逗點', 200, 180, 1, 1)
$a1 = GUICtrlCreateInput(_StringAddThousandsSep(7200), 10, 10, 80, 22, 0x01)
GUICtrlSetFont(-1, 12)
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd
Func _StringAddThousandsSep($sString, $sThousands = ",", $sDecimal = ".")
Local $sResult = ""
Local $aNumber = StringRegExp($sString, "(\d+)\D?(\d*)", 1)
If UBound($aNumber) = 2 Then
Local $sLeft = $aNumber
While StringLen($sLeft)
$sResult = $sThousands & StringRight($sLeft, 3) & $sResult
$sLeft = StringTrimRight($sLeft, 3)
WEnd
$sResult = StringTrimLeft($sResult, 1)
If $aNumber <> "" Then $sResult &= $sDecimal & $aNumber
EndIf
Return $sResult
EndFunc ;==>_StringAddThousandsSep afan 你好非常謝謝你
請問有沒有 簡短 的(我好幾個輸入框都要加逗點)
像底下這樣將$A1裡的數字格式化 成 加 , 逗點
GUICtrlSetData($A1,format格式化) 回复 3# tcpuuu GUICreate('千分位+逗點', 200, 180, 1, 1)
$a1 = GUICtrlCreateInput(7200, 10, 10, 80, 22, 0x01)
GUICtrlSetFont(-1, 12)
_InputFormat(-1)
$a2 = GUICtrlCreateInput(13200.33, 10, 40, 80, 22, 0x01)
GUICtrlSetFont(-1, 12)
_InputFormat(-1)
$a3 = GUICtrlCreateInput(5000, 10, 70, 80, 22, 0x01)
GUICtrlSetFont(-1, 12)
_InputFormat(-1)
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd
Func _InputFormat($iC)
Local $s = _StringAddThousandsSep(GUICtrlRead($iC))
GUICtrlSetData($iC, $s)
EndFunc ;==>_InputFormat
Func _StringAddThousandsSep($sString, $sThousands = ",", $sDecimal = ".")
Local $sResult = ""
Local $aNumber = StringRegExp($sString, "(\d+)\D?(\d*)", 1)
If UBound($aNumber) = 2 Then
Local $sLeft = $aNumber
While StringLen($sLeft)
$sResult = $sThousands & StringRight($sLeft, 3) & $sResult
$sLeft = StringTrimRight($sLeft, 3)
WEnd
$sResult = StringTrimLeft($sResult, 1)
If $aNumber <> "" Then $sResult &= $sDecimal & $aNumber
EndIf
Return $sResult
EndFunc ;==>_StringAddThousandsSep
afan 你好非常謝謝你
你真是很利害 樣樣都會
底下這個 請看看
只能按1次+1 , -1嗎?
我想 +100 and -100
---------------------------------
----------------------------
上下按紐 按1次 +100 -100 要如何做?
GUICreate('Updown',200,180,1,1)
$input = GUICtrlCreateInput("7200", 10, 10, 80, 22,0x01)
GUICtrlSetFont($input,12)
$updown = GUICtrlCreateUpdown($input)
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd 回复 5# tcpuuu
那个增量应该是系统默认的 回复 5# tcpuuu
#include <WindowsConstants.au3>
#include <EditConstants.au3>
Const $UDM_SETACCEL = $WM_USER + 107
Local $nSec = ["", 0, 2, 5], $nChg = ["", 100, 500, 2000]
Local $str = "uint;uint;uint;uint;uint;uint"
Local $AccelStruct = DllStructCreate($str )
For $i = 1 To 3
DllStructSetData($AccelStruct, ($i * 2) - 1, $nSec[$i])
DllStructSetData($AccelStruct, ($i * 2), $nChg[$i])
Next
GUICreate('Updown', 200, 180, 1, 1)
$input = GUICtrlCreateInput("7200", 10, 10, 80, 22, 0x01)
GUICtrlSetFont($input, 12)
$updown = GUICtrlCreateUpdown($input)
GUICtrlSendMsg($updown, $UDM_SETACCEL, 3, DllStructGetPtr ($AccelStruct))
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd
謝謝 happytc解說
這裡 很多高手學會很多
====================我的問題已解決================ 謝謝 happytc解說
這裡 很多高手學會很多
====================我的問題已解決================
tcpuuu 发表于 2011-10-10 00:56 http://www.autoitx.com/images/common/back.gif
呵,不客气
为了方便大家使用,我已经把这个写成UDF了,并且添加一些获取和设置Updown控件相关信息的函数,出坛右转:http://www.autoitx.com/forum.php?mod=viewthread&tid=27985&page=1&extra=#pid352280 回复 7# happytc
高人,GUICreate前面的没有看懂,对DLL一知半解! GUICreate('千分位+逗點', 200, 180, 1, 1)
$a1 = GUICtrlCreateInput(_StringAddThousandsSep(123456), 10, 50, 180, 22, 0x01)
GUICtrlSetFont(-1, 12)
$ParButton = GUICtrlCreateButton("更新數字後,一樣要有,逗點",1,1,146,30,0x01)
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
Case $ParButton
GUICtrlSetData($A1,'98765432')
EndSwitch
WEnd
Func _StringAddThousandsSep($sString, $sThousands = ",", $sDecimal = ".")
Local $sResult = ""
Local $aNumber = StringRegExp($sString, "(\d+)\D?(\d*)", 1)
If UBound($aNumber) = 2 Then
Local $sLeft = $aNumber
While StringLen($sLeft)
$sResult = $sThousands & StringRight($sLeft, 3) & $sResult
$sLeft = StringTrimRight($sLeft, 3)
WEnd
$sResult = StringTrimLeft($sResult, 1)
If $aNumber <> "" Then $sResult &= $sDecimal & $aNumber
EndIf
Return $sResult
EndFunc ;==>_StringAddThousandsSep 回复 11# tcpuuu
用4#的修改一下就行了GUICreate('千分位+逗點', 200, 180, 1, 1)
$a1 = GUICtrlCreateInput(_StringAddThousandsSep(123456), 10, 50, 180, 22, 0x01)
GUICtrlSetFont(-1, 12)
$ParButton = GUICtrlCreateButton("更新數字後,一樣要有,逗點", 1, 1, 146, 30, 0x01)
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
Case $ParButton
GUICtrlSetData($a1, '98765432')
_InputFormat($a1)
EndSwitch
WEnd
Func _InputFormat($iC)
Local $s = _StringAddThousandsSep(GUICtrlRead($iC))
GUICtrlSetData($iC, $s)
EndFunc ;==>_InputFormat
Func _StringAddThousandsSep($sString, $sThousands = ",", $sDecimal = ".")
Local $sResult = ""
Local $aNumber = StringRegExp($sString, "(\d+)\D?(\d*)", 1)
If UBound($aNumber) = 2 Then
Local $sLeft = $aNumber
While StringLen($sLeft)
$sResult = $sThousands & StringRight($sLeft, 3) & $sResult
$sLeft = StringTrimRight($sLeft, 3)
WEnd
$sResult = StringTrimLeft($sResult, 1)
If $aNumber <> "" Then $sResult &= $sDecimal & $aNumber
EndIf
Return $sResult
EndFunc ;==>_StringAddThousandsSep
afan 你好
底下這個 發現問題數值如果是 負的
有逗點 但是- 就不見
----------------------------------------GUICreate('千分位+逗點', 200, 180, 1, 1)
$s2 = GUICtrlCreateInput(_StringAddThousandsSep(10000), 10, 50, 180, 22, 0x01)
GUICtrlSetFont(-1, 12)
$s3 = GUICtrlCreateInput('-23546987', 10, 80, 180, 22, 0x01)
GUICtrlSetFont(-1, 12)
$ParButton = GUICtrlCreateButton("更新數字後,一樣要有,逗點", 1, 1, 146, 30, 0x01)
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
Case $ParButton
$i= GUICtrlRead($S2)
GUICtrlSetData($s2,$i)
_InputFormat($s2)
EndSwitch
WEnd
Func _InputFormat($iC)
Local $s = _StringAddThousandsSep(GUICtrlRead($iC))
GUICtrlSetData($iC, $s)
EndFunc ;==>_InputFormat
Func _StringAddThousandsSep($sString, $sThousands = ",", $sDecimal = ".")
Local $sResult = ""
Local $aNumber = StringRegExp($sString, "(\d+)\D?(\d*)", 1)
If UBound($aNumber) = 2 Then
Local $sLeft = $aNumber
While StringLen($sLeft)
$sResult = $sThousands & StringRight($sLeft, 3) & $sResult
$sLeft = StringTrimRight($sLeft, 3)
WEnd
$sResult = StringTrimLeft($sResult, 1)
If $aNumber <> "" Then $sResult &= $sDecimal & $aNumber
EndIf
Return $sResult
EndFunc ;==>_StringAddThousandsSep 回复 13# tcpuuu
_StringAddThousandsSep() 换成我写的那个 _NumFormat() 试试~
http://www.autoitx.com/thread-14377-1-1.html 回复 15# tcpuuu
贴代码请使用标签
[code]代码[/code]
现在这样既不美观也不方便,不好复制,不好说明哪行的问题等。
GUICtrlSetData($s1, _NumFormat($a))
页:
[1]
2