找回密码
 加入
搜索
查看: 6937|回复: 15

[AU3基础] [已解決] 修改$A1的數字為千分位+逗點

 火.. [复制链接]
发表于 2011-10-9 21:23:34 | 显示全部楼层 |阅读模式
本帖最后由 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的數字為千分位+逗點
发表于 2011-10-9 21:56:21 | 显示全部楼层
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[0]
                While StringLen($sLeft)
                        $sResult = $sThousands & StringRight($sLeft, 3) & $sResult
                        $sLeft = StringTrimRight($sLeft, 3)
                WEnd
                $sResult = StringTrimLeft($sResult, 1)
                If $aNumber[1] <> "" Then $sResult &= $sDecimal & $aNumber[1]
        EndIf
        Return $sResult
EndFunc   ;==>_StringAddThousandsSep
 楼主| 发表于 2011-10-9 22:13:19 | 显示全部楼层
afan 你好  非常謝謝你

請問有沒有 簡短 的(我好幾個輸入框都要加逗點)

像底下這樣  將$A1裡的數字格式化 成 加 , 逗點
GUICtrlSetData($A1,format格式化)
发表于 2011-10-9 23:06:42 | 显示全部楼层
回复 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[0]
                While StringLen($sLeft)
                        $sResult = $sThousands & StringRight($sLeft, 3) & $sResult
                        $sLeft = StringTrimRight($sLeft, 3)
                WEnd
                $sResult = StringTrimLeft($sResult, 1)
                If $aNumber[1] <> "" Then $sResult &= $sDecimal & $aNumber[1]
        EndIf
        Return $sResult
EndFunc   ;==>_StringAddThousandsSep
 楼主| 发表于 2011-10-9 23:28:43 | 显示全部楼层
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

本帖子中包含更多资源

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

×
发表于 2011-10-10 00:08:03 | 显示全部楼层
回复 5# tcpuuu


    那个增量应该是系统默认的
发表于 2011-10-10 00:40:02 | 显示全部楼层
回复 5# tcpuuu


   

#include <WindowsConstants.au3>
#include <EditConstants.au3>

Const $UDM_SETACCEL = $WM_USER + 107
Local $nSec[4] = ["", 0, 2, 5], $nChg[4] = ["", 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

 楼主| 发表于 2011-10-10 00:56:04 | 显示全部楼层
謝謝 happytc  解說
這裡 很多高手  學會很多
====================我的問題已解決================
发表于 2011-10-10 13:02:18 | 显示全部楼层
謝謝 happytc  解說
這裡 很多高手  學會很多
====================我的問題已解決================
tcpuuu 发表于 2011-10-10 00:56



    呵,不客气
为了方便大家使用,我已经把这个写成UDF了,并且添加一些获取和设置Updown控件相关信息的函数,出坛右转:http://www.autoitx.com/forum.php ... mp;extra=#pid352280
发表于 2011-10-10 22:26:42 | 显示全部楼层
回复 7# happytc
高人,GUICreate前面的没有看懂,对DLL一知半解!
 楼主| 发表于 2011-10-10 22:44:28 | 显示全部楼层
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[0]
                While StringLen($sLeft)
                        $sResult = $sThousands & StringRight($sLeft, 3) & $sResult
                        $sLeft = StringTrimRight($sLeft, 3)
                WEnd
                $sResult = StringTrimLeft($sResult, 1)
                If $aNumber[1] <> "" Then $sResult &= $sDecimal & $aNumber[1]
        EndIf
        Return $sResult
EndFunc   ;==>_StringAddThousandsSep

本帖子中包含更多资源

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

×
发表于 2011-10-10 23:10:05 | 显示全部楼层
回复 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[0]
                While StringLen($sLeft)
                        $sResult = $sThousands & StringRight($sLeft, 3) & $sResult
                        $sLeft = StringTrimRight($sLeft, 3)
                WEnd
                $sResult = StringTrimLeft($sResult, 1)
                If $aNumber[1] <> "" Then $sResult &= $sDecimal & $aNumber[1]
        EndIf
        Return $sResult
EndFunc   ;==>_StringAddThousandsSep
 楼主| 发表于 2011-10-11 15:02:35 | 显示全部楼层
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[0]
                While StringLen($sLeft)
                        $sResult = $sThousands & StringRight($sLeft, 3) & $sResult
                        $sLeft = StringTrimRight($sLeft, 3)
                WEnd
                $sResult = StringTrimLeft($sResult, 1)
                If $aNumber[1] <> "" Then $sResult &= $sDecimal & $aNumber[1]
        EndIf
        Return $sResult
EndFunc   ;==>_StringAddThousandsSep
发表于 2011-10-11 21:24:17 | 显示全部楼层
回复 13# tcpuuu


    _StringAddThousandsSep() 换成我写的那个 _NumFormat() 试试~
http://www.autoitx.com/thread-14377-1-1.html
发表于 2011-10-11 22:58:08 | 显示全部楼层
回复 15# tcpuuu


    贴代码请使用标签
[code]代码[/code]
现在这样既不美观也不方便,不好复制,不好说明哪行的问题等。

GUICtrlSetData($s1, _NumFormat($a))
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-13 23:59 , Processed in 0.087510 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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