Sign in to follow this  
Followers 0
Omga4000

Digit Grouping "On The Fly"

8 posts in this topic

Hello :)

I was wondering if it is possible to create a function that constantly checks the Input to see if Digit Grouping is needed.

(For example: If I write 1000 it automatically changes it to 1,000. Like the calculator does)

My code has Hebrew writing, but it shouldn't bother you much.

Here is my code:

#include
#include
#include
#include
#include
#include
#Region ### START Koda GUI section ### Form=c:\program files (x86)\autoit3\koda 1.7.30\forms\form1.kxf
$GoogleForm = GUICreate("Google Adwords", 321, 505, 617, 237)
$Budget_Label = GUICtrlCreateLabel("תקציב לפרסום בגוגל", 192, 24, 113, 17)
$Budget_Input = GUICtrlCreateInput("", 48, 20, 121, 21)
$Camp_Cost_Label = GUICtrlCreateLabel("*עלות ניהול קמפיין", 199, 68, 105, 17)
$Camp_Cost_Input = GUICtrlCreateInput("", 48, 64, 121, 21, $ES_READONLY)
$Click_Label = GUICtrlCreateLabel("עלות קליק (ממוצע)", 200, 112, 101, 17)
$Click_Input = GUICtrlCreateInput("", 48, 108, 121, 21)
$Land_Label = GUICtrlCreateLabel("*דף נחיתה ייעודי", 207, 156, 93, 17)
$Land_Input = GUICtrlCreateInput("", 48, 152, 121, 21)
$Phone_Label = GUICtrlCreateLabel("*פלאפון ייעודי", 220, 200, 84, 17)
$Phone_Combo = GUICtrlCreateCombo("", 48, 196, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL), $WS_EX_LAYOUTRTL)
GUICtrlSetData(-1, "לא|כן - ₪200")
$Profit_Label = GUICtrlCreateLabel("רווח מלקוח", 237, 244, 63, 17)
$Profit_Input = GUICtrlCreateInput("", 48, 240, 121, 21)
$Closing_Label = GUICtrlCreateLabel("יחס סגירה", 244, 288, 57, 17)
$Closing_Combo = GUICtrlCreateCombo("", 49, 284, 121, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL), $WS_EX_LAYOUTRTL)
GUICtrlSetData(-1, "1 מתוך 10|2 מתוך 10|3 מתוך 10|4 מתוך 10|5 מתוך 10|6 מתוך 10|7 מתוך 10|8 מתוך 10|9 מתוך 10|10 מתוך 10")
$OK_Button = GUICtrlCreateButton("!חשב", 136, 328, 75, 25)
$Expense_Label = GUICtrlCreateLabel("הוצאה שנתית", 213, 372, 74, 17)
$Expense_Input = GUICtrlCreateInput("", 64, 368, 121, 21)
$Income_Label = GUICtrlCreateLabel("הכנסה שנתית", 217, 416, 73, 17)
$Income_Input = GUICtrlCreateInput("", 64, 412, 121, 21)
$Total_Label = GUICtrlCreateLabel ("סה''כ רווח שנתי", 205, 460, 85, 17)
$Total_Input = GUICtrlCreateInput("", 64, 456, 121, 21)
$Label1 = GUICtrlCreateLabel("תשלום חד-פעמי*", 249, 488, 70, 17)
GUICtrlSetFont(-1, 8, 400, 0, "MS Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1

$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $OK_Button
$Budget = GUICtrlRead($Budget_Input)
If $Budget >= 10000 Then
GUICtrlSetData($Camp_Cost_Input, "30%")
EndIf
If $Budget <= 10000 AND $Budget >= 0.01 Then
GUICtrlSetData($Camp_Cost_Input, "15%")
Else
MsgBox (1, "!שגיאה", "!אנא הכנס תקציב")
EndIf

$Click = GUICtrlRead($Click_Input)
$oLand = GUICtrlRead($Land_Input)
If $oLand >= 1 AND $oLand <=9 Then ;Calculates the total cost of Landing Pages - Case 1-9
$nLand = $oLand * "550"
$fLand = $oLand & " x" & " 550" & "₪" & " = " & $nLand & "₪"
$var = StringMid($fLand, 1, 1)
_ResetInput($Land_Input)
$nLand = $var * "550"
$fLand = $var & " x" & " 550" & "₪" & " = " & $nLand & "₪"
GUICtrlSetData($Land_Input, $fLand)
EndIf

If $oLand >= 10 AND $oLand <=99 Then ;Calculates the total cost of Landing Pages - Case 10-99
$nLand = $oLand * "550"
$fLand = $oLand & " x" & " 550" & "₪" & " = " & $nLand & "₪"
$var = StringMid($fLand, 1, 2)
_ResetInput($Land_Input)
$nLand = $var * "550"
$fLand = $var & " x" & " 550" & "₪" & " = " & $nLand & "₪"
GUICtrlSetData($Land_Input, $fLand)
EndIf

If $oLand >= 100 Then ;Special order for god damn rich people!
MsgBox(1, "יש כסף, אה?", ":יא טחון.. צלצל להצעה" & @CR & "052-5317772")
$nLand = "1"
EndIf

$Phone = GUICtrlRead($Phone_Combo)
If $Phone = "כן - ₪200" Then
$Phone = 200
Else
$Phone = 0
EndIf
$Profit = GUICtrlRead($Profit_Input)
$Closing = GUICtrlRead($Closing_Combo)
$oExpense = $Budget*12 + $nLand + $Phone
$Expense = GUICtrlSetData($Expense_Input, $oExpense) ;Total Expense

$oBudget = GUICtrlRead($Budget_Input)
$oClick = GUICtrlRead($Click_Input)
$oClosing = GUICtrlRead($Closing_Combo)
$oProfit = GUICtrlRead($Profit_Input)

If $oClosing = "1 מתוך 10" Then
$oCash = $oBudget / $oClick * 0.1 * $oProfit * 12
GUICtrlSetData($Income_Input, $oCash) ;Total income 1/10
EndIf
If $oClosing = "2 מתוך 10" Then
$oCash = $oBudget / $oClick * 0.2 * $oProfit * 12
GUICtrlSetData($Income_Input, $oCash) ;Total income 2/10
EndIf
If $oClosing = "3 מתוך 10" Then
$oCash = $oBudget / $oClick * 0.3 * $oProfit * 12
GUICtrlSetData($Income_Input, $oCash) ;Total income 3/10
EndIf
If $oClosing = "4 מתוך 10" Then
$oCash = $oBudget / $oClick * 0.4 * $oProfit * 12
GUICtrlSetData($Income_Input, $oCash) ;Total income 4/10
EndIf
If $oClosing = "5 מתוך 10" Then
$oCash = $oBudget / $oClick * 0.5 * $oProfit * 12
GUICtrlSetData($Income_Input, $oCash) ;Total income 5/10
EndIf
If $oClosing = "6 מתוך 10" Then
$oCash = $oBudget / $oClick * 0.6 * $oProfit * 12
GUICtrlSetData($Income_Input, $oCash) ;Total income 6/10
EndIf
If $oClosing = "7 מתוך 10" Then
$oCash = $oBudget / $oClick * 0.7 * $oProfit * 12
GUICtrlSetData($Income_Input, $oCash) ;Total income 7/10
EndIf
If $oClosing = "8 מתוך 10" Then
$oCash = $oBudget / $oClick * 0.8 * $oProfit * 12
GUICtrlSetData($Income_Input, $oCash) ;Total income 8/10
EndIf
If $oClosing = "9 מתוך 10" Then
$oCash = $oBudget / $oClick * 0.9 * $oProfit * 12
GUICtrlSetData($Income_Input, $oCash) ;Total income 9/10
EndIf
If $oClosing = "10 מתוך 10" Then
$oCash = $oBudget / $oClick * $oProfit * 12
GUICtrlSetData($Income_Input, $oCash) ;Total income 10/10
EndIf

$var1 = GUICtrlRead($Expense_Input)
$var2 = GUICtrlRead($Income_Input)

$Total_Income_Cash = $var2 - $var1
GUICtrlSetData($Total_Input,$Total_Income_Cash)
EndSwitch
WEnd

Func _ResetInput($Land_Input)
GUICtrlSetData($Land_Input, "")
EndFunc

Anyone mind helping?

Best Regards,

Omga4000.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this:

#include <String.au3>
$i = 123456789
ConsoleWrite(Display1000Seperator($i) & @LF)
$i = 9876543210.99
ConsoleWrite(Display1000Seperator($i) & @LF)
$i = 100
ConsoleWrite(Display1000Seperator($i) & @LF)
$i = "55555"
ConsoleWrite(Display1000Seperator($i) & @LF)
$i = "99999.123"
ConsoleWrite(Display1000Seperator($i) & @LF)

Func Display1000Seperator($iNumber, $sSeperator = ",", $bFloat = False) ;coded by UEZ 2012
    If $iNumber = "" Then SetError(1, 0, 0)
    Local $1000
    If IsInt(Number($iNumber)) Then
        $1000 = _StringReverse(StringRegExpReplace(_StringReverse($iNumber), ".{3}", "$0" & $sSeperator))
        If StringLeft($1000, 1) = $sSeperator Then $1000 = StringTrimLeft($1000, 1)
        If $bFloat Then Return $1000 & ".00"
        Return $1000
    ElseIf IsFloat(Number($iNumber)) Then
        Local $1000 =  _StringReverse(StringRegExpReplace(_StringReverse(StringRegExpReplace($iNumber, "(\d+)\..*", "$1")), ".{3}", "$0" & $sSeperator))
        If StringLeft($1000, 1) = $sSeperator Then $1000 = StringTrimLeft($1000, 1)
        Return $1000 & StringRegExpReplace($iNumber, "\d+(\..*)", "$1")
    EndIf
    Return SetError(2, 0, 0)
EndFunc

For your code:

#include <String.au3>
#include <EditConstants.au3>
#include <ComboConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

#region ### START Koda GUI section ### Form=c:\program files (x86)\autoit3\koda 1.7.30\forms\form1.kxf
$GoogleForm = GUICreate("Google Adwords", 321, 505, 617, 237)
$Budget_Label = GUICtrlCreateLabel("תקציב ×œ×¤×¨×¡×•× ×‘×’×•×’×œ", 192, 24, 113, 17)
$Budget_Input = GUICtrlCreateInput("", 48, 20, 121, 21, $ES_NUMBER)
$Camp_Cost_Label = GUICtrlCreateLabel("*עלות × ×™×”×•×œ קמפיין", 199, 68, 105, 17)
$Camp_Cost_Input = GUICtrlCreateInput("", 48, 64, 121, 21, $ES_READONLY)
$Click_Label = GUICtrlCreateLabel("עלות קליק (ממוצע)", 200, 112, 101, 17)
$Click_Input = GUICtrlCreateInput("", 48, 108, 121, 21)
$Land_Label = GUICtrlCreateLabel("*דף × ×—×™×ª×” ייעודי", 207, 156, 93, 17)
$Land_Input = GUICtrlCreateInput("", 48, 152, 121, 21)
$Phone_Label = GUICtrlCreateLabel("*פל×פון ייעודי", 220, 200, 84, 17)
$Phone_Combo = GUICtrlCreateCombo("", 48, 196, 121, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL), $WS_EX_LAYOUTRTL)
GUICtrlSetData(-1, "ל×|כן - ₪200")
$Profit_Label = GUICtrlCreateLabel("רווח מלקוח", 237, 244, 63, 17)
$Profit_Input = GUICtrlCreateInput("", 48, 240, 121, 21)
$Closing_Label = GUICtrlCreateLabel("יחס סגירה", 244, 288, 57, 17)
$Closing_Combo = GUICtrlCreateCombo("", 49, 284, 121, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL), $WS_EX_LAYOUTRTL)
GUICtrlSetData(-1, "1 מתוך 10|2 מתוך 10|3 מתוך 10|4 מתוך 10|5 מתוך 10|6 מתוך 10|7 מתוך 10|8 מתוך 10|9 מתוך 10|10 מתוך 10")
$OK_Button = GUICtrlCreateButton("!חשב", 136, 328, 75, 25)
$Expense_Label = GUICtrlCreateLabel("הוצ××” ×©× ×ª×™×ª", 213, 372, 74, 17)
$Expense_Input = GUICtrlCreateInput("", 64, 368, 121, 21)
$Income_Label = GUICtrlCreateLabel("×”×›× ×¡×” ×©× ×ª×™×ª", 217, 416, 73, 17)
$Income_Input = GUICtrlCreateInput("", 64, 412, 121, 21)
$Total_Label = GUICtrlCreateLabel("סה''×› רווח ×©× ×ª×™", 205, 460, 85, 17)
$Total_Input = GUICtrlCreateInput("", 64, 456, 121, 21)
$Label1 = GUICtrlCreateLabel("×ª×©×œ×•× ×—×“-פעמי*", 249, 488, 70, 17)
GUICtrlSetFont(-1, 8, 400, 0, "MS Serif")
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

GUIRegisterMsg($WM_COMMAND, '_WM_COMMAND')
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $OK_Button
            $Budget = GUICtrlRead($Budget_Input)
            If $Budget >= 10000 Then
                GUICtrlSetData($Camp_Cost_Input, "30%")
            EndIf
            If $Budget <= 10000 And $Budget >= 0.01 Then
                GUICtrlSetData($Camp_Cost_Input, "15%")
            Else
                MsgBox(1, "!שגי××”", "!×× × ×”×›× ×¡ תקציב")
            EndIf

            $Click = GUICtrlRead($Click_Input)
            $oLand = GUICtrlRead($Land_Input)
            If $oLand >= 1 And $oLand <= 9 Then ;Calculates the total cost of Landing Pages - Case 1-9
                $nLand = $oLand * "550"
                $fLand = $oLand & " x" & " 550" & "₪" & " = " & $nLand & "₪"
                $var = StringMid($fLand, 1, 1)
                _ResetInput($Land_Input)
                $nLand = $var * "550"
                $fLand = $var & " x" & " 550" & "₪" & " = " & $nLand & "₪"
                GUICtrlSetData($Land_Input, $fLand)
            EndIf

            If $oLand >= 10 And $oLand <= 99 Then ;Calculates the total cost of Landing Pages - Case 10-99
                $nLand = $oLand * "550"
                $fLand = $oLand & " x" & " 550" & "₪" & " = " & $nLand & "₪"
                $var = StringMid($fLand, 1, 2)
                _ResetInput($Land_Input)
                $nLand = $var * "550"
                $fLand = $var & " x" & " 550" & "₪" & " = " & $nLand & "₪"
                GUICtrlSetData($Land_Input, $fLand)
            EndIf

            If $oLand >= 100 Then ;Special order for god damn rich people!
                MsgBox(1, "יש כסף, ××”?", ":×™× ×˜×—×•×Ÿ.. צלצל להצעה" & @CR & "052-5317772")
                $nLand = "1"
            EndIf

            $Phone = GUICtrlRead($Phone_Combo)
            If $Phone = "כן - ₪200" Then
                $Phone = 200
            Else
                $Phone = 0
            EndIf
            $Profit = GUICtrlRead($Profit_Input)
            $Closing = GUICtrlRead($Closing_Combo)
            $oExpense = $Budget * 12 + $nLand + $Phone
            $Expense = GUICtrlSetData($Expense_Input, $oExpense) ;Total Expense

            $oBudget = GUICtrlRead($Budget_Input)
            $oClick = GUICtrlRead($Click_Input)
            $oClosing = GUICtrlRead($Closing_Combo)
            $oProfit = GUICtrlRead($Profit_Input)

            If $oClosing = "1 מתוך 10" Then
                $oCash = $oBudget / $oClick * 0.1 * $oProfit * 12
                GUICtrlSetData($Income_Input, $oCash) ;Total income 1/10
            EndIf
            If $oClosing = "2 מתוך 10" Then
                $oCash = $oBudget / $oClick * 0.2 * $oProfit * 12
                GUICtrlSetData($Income_Input, $oCash) ;Total income 2/10
            EndIf
            If $oClosing = "3 מתוך 10" Then
                $oCash = $oBudget / $oClick * 0.3 * $oProfit * 12
                GUICtrlSetData($Income_Input, $oCash) ;Total income 3/10
            EndIf
            If $oClosing = "4 מתוך 10" Then
                $oCash = $oBudget / $oClick * 0.4 * $oProfit * 12
                GUICtrlSetData($Income_Input, $oCash) ;Total income 4/10
            EndIf
            If $oClosing = "5 מתוך 10" Then
                $oCash = $oBudget / $oClick * 0.5 * $oProfit * 12
                GUICtrlSetData($Income_Input, $oCash) ;Total income 5/10
            EndIf
            If $oClosing = "6 מתוך 10" Then
                $oCash = $oBudget / $oClick * 0.6 * $oProfit * 12
                GUICtrlSetData($Income_Input, $oCash) ;Total income 6/10
            EndIf
            If $oClosing = "7 מתוך 10" Then
                $oCash = $oBudget / $oClick * 0.7 * $oProfit * 12
                GUICtrlSetData($Income_Input, $oCash) ;Total income 7/10
            EndIf
            If $oClosing = "8 מתוך 10" Then
                $oCash = $oBudget / $oClick * 0.8 * $oProfit * 12
                GUICtrlSetData($Income_Input, $oCash) ;Total income 8/10
            EndIf
            If $oClosing = "9 מתוך 10" Then
                $oCash = $oBudget / $oClick * 0.9 * $oProfit * 12
                GUICtrlSetData($Income_Input, $oCash) ;Total income 9/10
            EndIf
            If $oClosing = "10 מתוך 10" Then
                $oCash = $oBudget / $oClick * $oProfit * 12
                GUICtrlSetData($Income_Input, $oCash) ;Total income 10/10
            EndIf

            $var1 = GUICtrlRead($Expense_Input)
            $var2 = GUICtrlRead($Income_Input)

            $Total_Income_Cash = $var2 - $var1
            GUICtrlSetData($Total_Input, $Total_Income_Cash)
    EndSwitch
WEnd

Func _ResetInput($Land_Input)
    GUICtrlSetData($Land_Input, "")
EndFunc   ;==>_ResetInput

Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $chk = BitAND($wParam, 0x0000FFFF)
    Switch $chk
        Case $Budget_Input
            GUICtrlSetData($Budget_Input, Display1000Seperator(StringReplace(GUICtrlRead($Budget_Input), ",", "")))
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func Display1000Seperator($iNumber, $sSeperator = ",", $bFloat = False) ;coded by UEZ 2012
    If $iNumber = "" Then SetError(1, 0, 0)
    Local $1000
    If IsInt(Number($iNumber)) Then
        $1000 = _StringReverse(StringRegExpReplace(_StringReverse($iNumber), ".{3}", "$0" & $sSeperator))
        If StringLeft($1000, 1) = $sSeperator Then $1000 = StringTrimLeft($1000, 1)
        If $bFloat Then Return $1000 & ".00"
        Return $1000
    ElseIf IsFloat(Number($iNumber)) Then
        Local $1000 =  _StringReverse(StringRegExpReplace(_StringReverse(StringRegExpReplace($iNumber, "(\d+)\..*", "$1")), ".{3}", "$0" & $sSeperator))
        If StringLeft($1000, 1) = $sSeperator Then $1000 = StringTrimLeft($1000, 1)
        Return $1000 & StringRegExpReplace($iNumber, "\d+(\..*)", "$1")
    EndIf
    Return SetError(2, 0, 0)
EndFunc   ;==>Display1000Seperator

If did it only for the 1st input control ($Budget_Input).

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thank you, that works beautifully!

However, now I have another problem. The program doesn't recognize "1,000" as "1000", but as "1".

Do I need to define the numbers as Int?

Edited by Omga4000

Share this post


Link to post
Share on other sites

You have to convert it back to an integer by replacing the "," with "".

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

A simple implementation with regular expressions

GUI - Example

#include-once
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>

#cs
Keypoints : Commas are added after every third digit
-Digits after a decimal are ignored
#ce

Local $hGUI = GUICreate ( @ScriptName & ' |Phoenix XL', 500, 300 )
Global $iEdit = GUICtrlCreateEdit ( '', 10, 30, 480, 200, $ES_WANTRETURN )
GUICtrlCreateLabel( 'Type Numbers, Commas are automatically added', 10, 10, 450, 20 )
Local $iButton = GUICtrlCreateButton ( 'Get the Original Numbers', 10, 260, 200, 30 )
GUIRegisterMsg ( $WM_COMMAND, 'WM_COMMAND' )
GUISetState( )

Local $sText
While 1
Switch GUIGetMsg()
Case -3 ; GUI_EVENT_CLOSE
ExitLoop
Case $iButton
$sText = RemoveComma ( GUICtrlRead( $iEdit ) )
GUIDelete ()
If $sText Then MsgBox ( 64, 'Exitting', $sText )
EndSwitch
WEnd

Func WM_COMMAND( $hWnd, $iMsg, $wParam, $lParam )
Local $nCode = _WinAPI_HiWord ( $wParam )
Switch $nCode
Case $EN_CHANGE
Local $sRead = RemoveComma ( GUICtrlRead( $iEdit ) )
GUICtrlSetData( $iEdit , AddComma ( $sRead ) )
EndSwitch
EndFunc

;For Adding Commas to Numbers
Func AddComma ( $sDigit )
SetExtended ( 1 )
While @extended
$sDigit = StringRegExpReplace ( $sDigit, '(?m)(^|[^.\d])(\d+)(\d{3})', '\1\2,\3' )
WEnd
Return $sDigit
EndFunc

;For Removing the Added Commas
Func RemoveComma ( $sString )
SetExtended ( 1 )
While @extended
$sString = StringRegExpReplace ( $sString, '(\d+)(,)(\d{3})', '\1\3' )
WEnd
Return $sString
EndFunc

Msgbox - Example

Local $iDigits[5] = ['1234555235', ' 1245 1542 5 135 352354254325 ', _
'1232143.4535','f3423556', 'Phoenix XL']
Local $sTemp
For $i = 0 To 4
$sTemp = AddComma($iDigits[$i])
Display ( $iDigits[$i], $sTemp, 'Adding Commas' )
Display ( $sTemp, RemoveComma($sTemp), 'Removing Commas' )
Next

;For Adding Commas to Numbers
Func AddComma($sDigit)
SetExtended(1)
While @extended
$sDigit = StringRegExpReplace($sDigit, '(?m)(^|[^.\d])(\d+)(\d{3})', '\1\2,\3')
WEnd
Return $sDigit
EndFunc ;==>AddComma

;For Removing the Added Commas
Func RemoveComma($sString)
SetExtended(1)
While @extended
$sString = StringRegExpReplace($sString, '(\d+)(,)(\d{3})', '\1\3')
WEnd
Return $sString
EndFunc ;==>RemoveComma

Func Display ( $sInput, $sOutput, $sTitle )
MsgBox( 64, $sTitle, StringFormat('Input: %s\nOutput: %s\n\n', $sInput , $sOutput ) )
EndFunc
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

PhoenixXL,

I changed your gui example to update the input control in place when the button to revert is actioned. You were deleting the gui but remaining in the message loop. See comments in the code.

#include-once
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>

#cs
    Keypoints : Commas are added after every third digit
    -Digits after a decimal are ignored
#ce

Local $hGUI = GUICreate(@ScriptName & ' |Phoenix XL', 500, 300)
Global $iEdit = GUICtrlCreateEdit('', 10, 30, 480, 200, $ES_WANTRETURN)
GUICtrlCreateLabel('Type Numbers, Commas are automatically added', 10, 10, 450, 20)
Local $iButton = GUICtrlCreateButton('Get the Original Numbers', 10, 260, 200, 30)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
GUISetState()

Local $sText
While 1
    Switch GUIGetMsg()
        Case -3 ; GUI_EVENT_CLOSE
            ExitLoop
        Case $iButton
            guictrlsetdata($iedit, RemoveComma(GUICtrlRead($iEdit)))  ; <- added this as the gui was deleted but the message loop keeps running - deleted the msgbox and guidelete stmts
    EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $nCode = _WinAPI_HiWord($wParam)
    Switch $nCode
        Case $EN_CHANGE
            Local $sRead = RemoveComma(GUICtrlRead($iEdit))
            GUICtrlSetData($iEdit, AddComma($sRead))
    EndSwitch
EndFunc   ;==>WM_COMMAND

;For Adding Commas to Numbers
Func AddComma($sDigit)
    SetExtended(1)
    While @extended
        $sDigit = StringRegExpReplace($sDigit, '(?m)(^|[^.\d])(\d+)(\d{3})', '\1\2,\3')
    WEnd
    Return $sDigit
EndFunc   ;==>AddComma

;For Removing the Added Commas
Func RemoveComma($sString)
    SetExtended(1)
    While @extended
        $sString = StringRegExpReplace($sString, '(\d+)(,)(\d{3})', '\1\3')
    WEnd
    Return $sString
EndFunc   ;==>RemoveComma

Can you PLEASE explain the regular exp<b></b>ression pattern that you are using in the AddComma function?

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

Another example >>


_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

Share this post


Link to post
Share on other sites

Can you PLEASE explain the regular expression pattern that you are using in the AddComma function?

For Sure :)

;For Adding Commas to Numbers
Func AddComma($sDigit)
    SetExtended(1)
    While @extended
        $sDigit = StringRegExpReplace($sDigit, _
'(?m)(^|[^.\d])' & _ ; [First Group] The character preceding a digit(s) can be the starting of the string but not a "digit" or a "decimal point"
'(\d+)(\d{3})', ; [Second Group] Atleast one digit after which [Third Group] three digits are present
'\1\2,\3' _ ; Insert a Comma after the Second Group
) ; This loop runs until no match is found
    WEnd
    Return $sDigit
EndFunc   ;==>AddComma

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • zxtnt09
      By zxtnt09
      Hi guys,
      i was use that, to know "Username" is create or not,etc.
      but i have problem
      #include <IE.au3> #include <INet.au3> #include <String.au3> signIn() Func signIn () Global $oIE = _IECreate ("https://login.yahoo.com/config/login") Local $username = _IEGetObjByName ($oIE,"username") Local $password = _IEGetObjByName ($oIE,"passwd") Local $btn = _IEGetObjByName ($oIE,"signin") _IEFormElementSetValue ($username,"AsdfavsdASWddsaA") _IEFormElementSetValue ($password,"123456") _IEAction ($btn,"click") $url = "https://login.yahoo.com/config/login" $first = '<html>' $end = '</html>' $read = _StringBetween(_INetGetSource($url), $first, $end) If $read[0] == "This ID is not yet taken." Then MsgBox (16,"","This ID is not create yet!") Else MsgBox (16,"","This ID was created!") EndIf EndFunc Please help i'll be die with errors 
    • TheOnlyOne
      By TheOnlyOne
      So i have been trying to find a way to auto update my SVN repo whenever someone commit a new file
       
      I found this commandline from google and i can get that to work with autoit np
      CD C:\Program Files\TortoiseSVN\bin\ START TortoiseProc.exe /command:update /path:"C:\www\MyRepo\" /closeonend:0 But what i want is everytime someone commits something and my repo aint the newest version, i want it to run the commandline.
      I tried googling and can't find anything
      is this even possible, if it is how? can you get the newest version with a command line to and compare it to your own version maybe ?
      Thanks