Jump to content

How to update Input with coma(,) separator?


stalliont
 Share

Recommended Posts

Hello all I tried to search but couldn't find a solution.

What I want is when the user enters numbers with 3 digits is to enter a coma(",") to separate each 1000.

For example if I enter 1000 into the input box, it will update it to 1,000 or better $1,000

Another example is when I enter 900500 I want it to show $900,500 etc

Please help how could I do it?

#include <GUIConstants.au3>
    
$GUI_Price = GUICreate("Enter Price", 191, 85, -1, -1, $WS_POPUP+$WS_CAPTION)
$Input_Price = GUICtrlCreateInput("", 0, 0, 180, 20)
;GUICtrlSetLimit(-1,10)
$Button_1 = GUICtrlCreateButton("Save", 20, 40, 60, 20)
$Button_2 = GUICtrlCreateButton("Cancel", 100, 40, 60, 20)
$set = 0

GUISetState()
Do
    $msg = GUIGetMsg()

    If GuiCtrlRead($Input_Price) >= 999 and $set <> 1 Then
        GuiCtrlSetData($Input_Price, GuiCtrlRead($Input_Price) & ",")
        $set = 1
    ElseIf GuiCtrlRead($Input_Price) < 999 and $set = 1 Then
        $set = 0
    EndIf
    If GuiCtrlRead($Input_Price) = "999,999" Then
        GuiCtrlSetData($Input_Price, GuiCtrlRead($Input_Price) & ",")
        $set = 1
    EndIf

    If $msg = $Button_2 Then
        Exit
    EndIf
    
Until $msg = $GUI_EVENT_CLOSE

As you can see I tried using If, Else statement but didn't work as I wanted.

Link to comment
Share on other sites

You'd expect to find it in StringFormat, wouldn't you?

Nope I tried looking at StringFormat, Its used for numbers and can put decimals, but I couldn't make it to put comas after a user type in certain numbers to represent each 3 digits for thousands. EG user input 9999 = 9,999. User input 99999 = 99,999. user input 999999 = 999,999 user input 9999999 = 9,999,999 etc

And when I use GuiCtrlRead($input) I get 9,999 with comas, soI used StringSplit and add them together to get 9999 back. But gets stuck somewhere. And also tried StringInsert didn't work too well.

I wonder if there is an easier way.

Link to comment
Share on other sites

i made this a while back

Dim $t = 0, $Final

$Totallines = "1234567890"

$result = StringSplit($Totallines, "")

For $x = $result[0] to 1 step -1
    $t = $t + 1
    If $t = 4 And $x < $result[0] Then
        $Final = $result[$x] & "," & $Final
        $t = 1
        ContinueLoop
    Else
        $Final = $result[$x] & $Final
    EndIf
Next

MsgBox(0,"Final Result", $Final)

8)

NEWHeader1.png

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...