Jump to content

Gui Input And Label (thousandth's Question)


Recommended Posts

i have a gui with an input where the user inputs a number for a price, they then click a button and the price is multiplied against different variables and output to a label.

what i would love to figure out is how to have both show thousandths comma's

i.e. 1000 would equal 1,000

1000000 would be 1,000,000

any help would be appreciated, i have seen a post about a phone number input where it adds the ( ) automatically but was hoping there was an easier way.

thanks in advance,

tim houser

Edited by saturnknts
Link to comment
Share on other sites

O jesus i quit quit quit quit its driving me crazy

FINE, delete my post. IF YOU THINK I AM THAT STUPID. I have been learning the new gui on my own going through almost every post, doing searches on my own and i was looking for an easy answer. i guess i should just spend another week looking around.

and if you think i am a novice or afraid of hard work and determination, go look at the autoit version 1 reference examples to find my windows 95 script. look under tim houser

i am sure it's something simple and i am overlooking it.

i'd sure like to know how i deserve your response? if you're not going to help, why even post?

Link to comment
Share on other sites

use the search button at the top of this page

http://www.autoitscript.com/forum/index.ph...=22396&hl=,000#

8)

that's what i was hoping to get as a response. as you can see by my post i was searching "thousand" and for some never thought to search "1000".

thank you Valuater

and thatsgreat2345 i'm am sorry it was too much to ask, but thanks for making it feel homey around here!

Link to comment
Share on other sites

hahah i wasnt making fun of you i got it to work up to 100,000 just after that i couldnt :) not making fun of you in anyway making fun of myself now i got to go check out that post and see how the crap they did it

fair enough, i am sorry i took it wrong then. just tired and stressed over all this learning!

tim

Link to comment
Share on other sites

Just another, RegExp driven variant of the same thing:

Func _Thousands($nStr)
    If not StringIsDigit($nStr) and not StringIsFloat($nStr) then
        SetError(1)
        Return ""
    EndIf
    Local $sResult, $aResult
    $aResult = StringRegExp($nStr, "^(\d{1,3}?)(\d{3})+(\p\d+)?$", 1)
    If @extended Then
        $sResult = $aResult[0]
        For $i = 1 to UBound($aResult) - 1
            $sResult &= "," & $aResult[$i]
        Next
    Else
        $sResult = $nStr
    EndIf
    Return StringReplace($sResult, ",.", ".")
EndFunc
Link to comment
Share on other sites

i know it's clunky but here is what i came up with. it's effective and thats all i care about lol.

Case $msg = $calcprice
            
            $sell = Round(($npc*2+$npcint+$npcintstr+$npcplus+$npccrit+$npcblock+$npcsos)*$pressurex)
            $error = GUICtrlRead($inputnpcprice)
            $sell2 = String($sell)
                        
            Select  
                case $error = Asc($s_char) >= 48 And Asc($s_char) <= 57
                    MsgBox (0, "Enter the Buy or Cost Price First!", "You must Enter the Buy or Cost Price First!")
                Case $sell2 <= 999
                    $sell3 = $sell  
                case $sell2 <= 9999
                    $hund = StringRight($sell2,3)
                    $thous = Stringleft($sell2,1)
                    $sell3 = ($thous & "," & $hund)
                case $sell2 <= 99999
                    $hund = StringRight($sell2,3)
                    $thous = Stringleft($sell2,2)
                    $sell3 = ($thous & "," & $hund)
                case $sell2 <= 999999
                    $hund = StringRight($sell2,3)
                    $thous = Stringleft($sell2,3)
                    $sell3 = ($thous & "," & $hund)
                case $sell2 <= 9999999
                    $hund = StringRight($sell2,3)
                    $thous = Stringmid($sell2,2,3)
                    $mill = Stringleft($sell2,1)
                    $sell3 = ($mill& "," & $thous & "," & $hund)
                case $sell2 <= 99999999
                    $hund = StringRight($sell2,3)
                    $thous = Stringmid($sell2,3,3)
                    $mill = Stringleft($sell2,2)
                    $sell3 = ($mill& "," & $thous & "," & $hund)
                case $sell2 <= 999999999
                    $hund = StringRight($sell2,3)
                    $thous = Stringmid($sell2,4,3)
                    $mill = Stringleft($sell2,3)
                    $sell3 = ($mill& "," & $thous & "," & $hund)
                case $sell2 >1000000000
                    Msgbox(0, "ummmmmmm", "Are You Crazy?  That's way too much;)")
            EndSelect
Edited by saturnknts
Link to comment
Share on other sites

  • Moderators

Did you try LazyCats? Would have saved you alot of time and speed:

MsgBox(0, '', _Thousands(100000000000.02))
Func _Thousands($nStr)
    If not StringIsDigit($nStr) and not StringIsFloat($nStr) then
        SetError(1)
        Return ""
    EndIf
    Local $sResult, $aResult
    $aResult = StringRegExp($nStr, "^(\d{1,3}?)(\d{3})+(\p\d+)?$", 1)
    If @extended Then
        $sResult = $aResult[0]
        For $i = 1 to UBound($aResult) - 1
            $sResult &= "," & $aResult[$i]
        Next
    Else
        $sResult = $nStr
    EndIf
    Return "$" & StringReplace($sResult, ",.", ".")
EndFunc
Using LazyCat's UDF

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

my mind was to full of things and this was the easiest was i could decide to do it and make sense in my mind. but now that my program is complete i might go back and test it once again so as to reduce a little bit of code. :) tim

Did you try LazyCats? Would have saved you alot of time and speed:

MsgBox(0, '', _Thousands(100000000000.02))
Func _Thousands($nStr)
    If not StringIsDigit($nStr) and not StringIsFloat($nStr) then
        SetError(1)
        Return ""
    EndIf
    Local $sResult, $aResult
    $aResult = StringRegExp($nStr, "^(\d{1,3}?)(\d{3})+(\p\d+)?$", 1)
    If @extended Then
        $sResult = $aResult[0]
        For $i = 1 to UBound($aResult) - 1
            $sResult &= "," & $aResult[$i]
        Next
    Else
        $sResult = $nStr
    EndIf
    Return "$" & StringReplace($sResult, ",.", ".")
EndFunc
Using LazyCat's UDF
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...