Sign in to follow this  
Followers 0
drunkfux

Need help with tax calculator

21 posts in this topic

Made a simple calculator for @ work to calculate a price based upon our retailersprice, then add 19% VAT (tax) and then add a custom profitpercentage..

It all works how i want it to except if the input is a number with a comma in it for example 10,50

If i use a point as decimal then it works fine like 10.50

Why does the calculation mess up when i use a comma and how can i fix it?

Here's the script:

#include <GuiConstants.au3>

$clipboardcontent = ClipGet()

GuiCreate("BTW Calc", 645, 65, (@DesktopWidth-178)/4, (@DesktopHeight-158)/3, -1)

WinSetOnTop ( "BTW Calc", "", 1)

;-----------------------------------------------------------------------------------

$InkoopLabel = GuiCtrlCreateLabel("Inkoop ex BTW   ", 10, 24, 100, 20)
$Inkoop = GuiCtrlCreateInput($clipboardcontent, 105, 21, 80, 20)

;-----------------------------------------------------------------------------------

$VastPercentage = GuiCtrlCreateLabel("Vast Percentage", 210, 12, 85, 20)

$5percentbutton = GuiCtrlCreateButton("5%", 300, 9, 40, 20)
$10percentbutton = GuiCtrlCreateButton("10%", 345, 9, 40, 20)
$15percentbutton = GuiCtrlCreateButton("15%", 390, 9, 40, 20)
$20percentbutton = GuiCtrlCreateButton("20%", 390, 35, 40, 20)

$EigenPercentage = GuiCtrlCreateLabel("Eigen Percentage", 210, 37, 95, 20)

$custompercentbutton = GuiCtrlCreateButton("OK", 345, 35, 40, 20)
$custompercentinput = GUICtrlCreateInput("", 300, 35, 40, 20)

;-----------------------------------------------------------------------------------

$verkoopadviesexprijs = GuiCtrlCreateInput("", 555, 9, 80, 20)
$verkoopadviesexprijsLabel = GuiCtrlCreateLabel("Verkoop -- BTW  ", 455, 12, 90, 20)

$verkoopadviesprijs = GuiCtrlCreateInput("", 555, 34, 80, 20)
$verkoopadviesprijsLabel = GuiCtrlCreateLabel("Verkoop + BTW  ", 455, 37, 90, 20)

;-----------------------------------------------------------------------------------

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    
Case $msg = $5percentbutton
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs2 = $prijs1 / 100
        $prijs3 = $prijs2 * 119
        $prijs4 = $prijs3 / 100
        $5percentbuttonProfit = $prijs4 * 105
        $afgerond1 = Round($5percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesprijs, $afgerond1)
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs4 = $prijs1 / 100
        $5percentbuttonProfit = $prijs4 * 105
        $afgerond2 = Round($5percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesexprijs, $afgerond2)

    Case $msg = $10percentbutton
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs2 = $prijs1 / 100
        $prijs3 = $prijs2 * 119
        $prijs4 = $prijs3 / 100
        $10percentbuttonProfit = $prijs4 * 110
        $afgerond1 = Round($10percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesprijs, $afgerond1)
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs4 = $prijs1 / 100
        $10percentbuttonProfit = $prijs4 * 110
        $afgerond2 = Round($10percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesexprijs, $afgerond2)

    Case $msg = $15percentbutton
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs2 = $prijs1 / 100
        $prijs3 = $prijs2 * 119
        $prijs4 = $prijs3 / 100
        $15percentbuttonProfit = $prijs4 * 115
        $afgerond1 = Round($15percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesprijs, $afgerond1)
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs4 = $prijs1 / 100
        $15percentbuttonProfit = $prijs4 * 115
        $afgerond2= Round($15percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesexprijs, $afgerond2)

    Case $msg = $20percentbutton
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs2 = $prijs1 / 100
        $prijs3 = $prijs2 * 119
        $prijs4 = $prijs3 / 100
        $20percentbuttonProfit = $prijs4 * 120
        $afgerond1 = Round($20percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesprijs, $afgerond1)
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs4 = $prijs1 / 100
        $20percentbuttonProfit = $prijs4 * 120
        $afgerond2 = Round($20percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesexprijs, $afgerond2)
        
    Case $msg = $custompercentbutton
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs2 = $prijs1 / 100
        $prijs3 = $prijs2 * 119
        $prijs4 = $prijs3 / 100
        $custompercentbuttonProfit = $prijs4 * Number(100 + Number(GUICtrlRead($custompercentinput)))
        $afgerond1 = Round($custompercentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesprijs, $afgerond1)
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs4 = $prijs1 / 100
        $custompercentbuttonProfit = $prijs4 * Number(100 + Number(GUICtrlRead($custompercentinput)))
        $afgerond2= Round($custompercentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesexprijs, $afgerond2)
    
    Case Else
  ;;;
    EndSelect
WEnd
Exit

Share this post


Link to post
Share on other sites



you could try something like:

$prijs1 = StringReplace($prijs1, ",", ".")

I will look into it.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

you could try something like:

$prijs1 = StringReplace($prijs1, ",", ".")

I will look into it.

Just tried it and it seems to work, thank you very much.. If u do find any bugs pls let me know :)

#include <GuiConstants.au3>

$clipboardcontent = ClipGet()

GuiCreate("BTW Calc", 645, 65, (@DesktopWidth-178)/4, (@DesktopHeight-158)/3, -1)

WinSetOnTop ( "BTW Calc", "", 1)

;-----------------------------------------------------------------------------------

$InkoopLabel = GuiCtrlCreateLabel("Inkoop ex BTW   €", 10, 24, 100, 20)
$Inkoop = GuiCtrlCreateInput($clipboardcontent, 105, 21, 80, 20)

;-----------------------------------------------------------------------------------

$VastPercentage = GuiCtrlCreateLabel("Vast Percentage", 210, 12, 85, 20)

$5percentbutton = GuiCtrlCreateButton("5%", 300, 9, 40, 20)
$10percentbutton = GuiCtrlCreateButton("10%", 345, 9, 40, 20)
$15percentbutton = GuiCtrlCreateButton("15%", 390, 9, 40, 20)
$20percentbutton = GuiCtrlCreateButton("20%", 390, 35, 40, 20)

$EigenPercentage = GuiCtrlCreateLabel("Eigen Percentage", 210, 37, 95, 20)

$custompercentbutton = GuiCtrlCreateButton("OK", 345, 35, 40, 20)
$custompercentinput = GUICtrlCreateInput("", 300, 35, 40, 20)

;-----------------------------------------------------------------------------------

$verkoopadviesexprijs = GuiCtrlCreateInput("", 555, 9, 80, 20)
$verkoopadviesexprijsLabel = GuiCtrlCreateLabel("Verkoop -- BTW  €", 455, 12, 90, 20)

$verkoopadviesprijs = GuiCtrlCreateInput("", 555, 34, 80, 20)
$verkoopadviesprijsLabel = GuiCtrlCreateLabel("Verkoop + BTW  €", 455, 37, 90, 20)

;-----------------------------------------------------------------------------------

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    
Case $msg = $5percentbutton
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs1 = StringReplace($prijs1, ",", ".")
        $prijs2 = $prijs1 / 100
        $prijs3 = $prijs2 * 119
        $prijs4 = $prijs3 / 100
        $5percentbuttonProfit = $prijs4 * 105
        $afgerond1 = Round($5percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesprijs, $afgerond1)
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs1 = StringReplace($prijs1, ",", ".")
        $prijs4 = $prijs1 / 100
        $5percentbuttonProfit = $prijs4 * 105
        $afgerond2 = Round($5percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesexprijs, $afgerond2)

    Case $msg = $10percentbutton
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs1 = StringReplace($prijs1, ",", ".")
        $prijs2 = $prijs1 / 100
        $prijs3 = $prijs2 * 119
        $prijs4 = $prijs3 / 100
        $10percentbuttonProfit = $prijs4 * 110
        $afgerond1 = Round($10percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesprijs, $afgerond1)
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs1 = StringReplace($prijs1, ",", ".")
        $prijs4 = $prijs1 / 100
        $10percentbuttonProfit = $prijs4 * 110
        $afgerond2 = Round($10percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesexprijs, $afgerond2)

    Case $msg = $15percentbutton
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs1 = StringReplace($prijs1, ",", ".")
        $prijs2 = $prijs1 / 100
        $prijs3 = $prijs2 * 119
        $prijs4 = $prijs3 / 100
        $15percentbuttonProfit = $prijs4 * 115
        $afgerond1 = Round($15percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesprijs, $afgerond1)
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs1 = StringReplace($prijs1, ",", ".")
        $prijs4 = $prijs1 / 100
        $15percentbuttonProfit = $prijs4 * 115
        $afgerond2= Round($15percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesexprijs, $afgerond2)

    Case $msg = $20percentbutton
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs1 = StringReplace($prijs1, ",", ".")
        $prijs2 = $prijs1 / 100
        $prijs3 = $prijs2 * 119
        $prijs4 = $prijs3 / 100
        $20percentbuttonProfit = $prijs4 * 120
        $afgerond1 = Round($20percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesprijs, $afgerond1)
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs1 = StringReplace($prijs1, ",", ".")
        $prijs4 = $prijs1 / 100
        $20percentbuttonProfit = $prijs4 * 120
        $afgerond2 = Round($20percentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesexprijs, $afgerond2)
        
    Case $msg = $custompercentbutton
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs1 = StringReplace($prijs1, ",", ".")
        $prijs2 = $prijs1 / 100
        $prijs3 = $prijs2 * 119
        $prijs4 = $prijs3 / 100
        $custompercentbuttonProfit = $prijs4 * Number(100 + Number(GUICtrlRead($custompercentinput)))
        $afgerond1 = Round($custompercentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesprijs, $afgerond1)
        $prijs1 = GUICtrlRead($Inkoop)
        $prijs1 = StringReplace($prijs1, ",", ".")
        $prijs4 = $prijs1 / 100
        $custompercentbuttonProfit = $prijs4 * Number(100 + Number(GUICtrlRead($custompercentinput)))
        $afgerond2= Round($custompercentbuttonProfit,2)
        GUICtrlSetData ($verkoopadviesexprijs, $afgerond2)
    
    Case Else
  ;;;
    EndSelect
WEnd
Exit
Edited by drunkfux

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

you could try something like:

$prijs1 = StringReplace($prijs1, ",", ".")oÝ÷ Ø"Yh¢H§¶­þ«¨µäáÉÉ·«z¨¨©©à¹¨±ëmx,¥ç"~'¡ª®É-zËm¢Ç2¢êìÊË^§vW¬uç"©i¢)í±©Ý¶.±©Ý²Ç©z¶­¢»ºÚ"µÍÚ[HBIÌÍÖH[]Þ
    ][ÝÕÝX]  ][ÝË  ][ÝÑ[[X   ][ÝÊBRYÜ[^]IÌÍÌH  ÌÍÖ
IÌÍÒ[H   ÌÍÖÈSÙÐÞ
    ][ÝÔÝ[   ][ÝË  ][ÝÒ[]    ][ÝÈ  [È ÌÍÖ  [ÈÔ   [È ][ÝÑÝXY  ][ÝÈ  [È ÌÍÌ  [ÈÔ   [È ][ÝÒ[Y    ][ÝÈ  [È ÌÍÒ[
BÑ[

When I run it with "1,234.50" it clips the input to "1".

:)

Edit: Changed "is" to "may be"... not sure.

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

This may be reqional/language setting specific, do a quick test to see how your system handles decimal points and thousands seperators:

While 1
    $X = InputBox("Test Math", "Enter number:  ")
    If @error Then Exit
    $2X = $X * 2
    $HalfX = $X / 2
    MsgBox(64, "Result", "Input:  " & $X & @CRLF & "Doubled:  " & $2X & @CRLF & "Halved:  " & $HalfX)
WEnd

When I run it with "1,234.50" it clips the input to "1".

:)

Edit: Changed "is" to "may be"... not sure.

Tried your test script with 10.000,00 as input.. results aren't good :P

Posted Image

Share this post


Link to post
Share on other sites

It is a language specific setting, in reginoal settings in the control panel.

can be located in the registry and depending on the decimal delimiter it can be handled differently.

HKCU\Control Panel\International\

sDecimal is the Decimal delimiter and iCurrDigits is number of digits after decimal.

sThousand is the thousand delimiter. I think you will find something to work with there.

look in the control panel/regional settings to see what the rest of the values are.

/J


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Tried your test script with 10.000,00 as input.. results aren't good :)

Posted Image

I can't screw around with this machine to test it, but possibly AutoIT's interpreter only sees these numbers one way, regardless of the regional setting. If that is the case, then some translation inside your script is necessary to remove the thousands seperator, regardless of what it is -- and make the decimal point a period, regardless of what it was. We get the pointer to the reg keys from jinxter. I think the two we are interested in are sDecimal and sThousand. Here's a tweaked version of my earlier test script, which should be fairly immune to regional settings:

$sDecimal = RegRead("HKCU\Control Panel\International", "sDecimal")
$sThousand = RegRead("HKCU\Control Panel\International", "sThousand")

While 1
    $X = InputBox("Test Math", "Enter number:  ")
    If @error Then Exit
    $X = StringReplace($X, $sThousand, "")
    $X = StringReplace($X, $sDecimal, ".")
    $2X = $X * 2
    $HalfX = $X / 2
    $X = StringReplace(String($X), ".", $sDecimal)
    $2X = StringReplace(String($2X), ".", $sDecimal)
    $HalfX = StringReplace(String($HalfX), ".", $sDecimal)
    MsgBox(64, "Result", "Input:  " & $X & @CRLF & "Doubled:  " & $2X & @CRLF & "Halved:  " & $HalfX)
WEnd

Tested it with US-EN settings and 10,240.25 for input and it worked. Would be interested to know if anyone using other international settings have any trouble with it.

:P

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

That was basically what I was thinking could be done.

Input: 10,240.25 (changes to 10,240,25)

Doubled: 20,48

Halved: 5,12

same with 10.240,25

Regional setting sv (swedish)

I guess it's not counting regardless what the setting is. you have to see what the value is in the registry and translate accoring to that value. could be a tough cookie to crack, if you don't omit the decimal (as a decimal sign in sweden is a comma, in US it's a dot ?) using a different editbox or something. or if the 3rd char from the right is either a decimal or a dot , change it to the regional settings value of a decimal. And change every 4th value thereafter from the right to the value of thousand delimiter.

there must be an easier way...

Edited by jinxter

> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

$sDecimal = RegRead("HKCU\Control Panel\International", "sDecimal")
$sThousand = RegRead("HKCU\Control Panel\International", "sThousand")

While 1
    $X = InputBox("Test Math", "Enter number:  ")
    If @error Then Exit
    $X = StringReplace($X, $sThousand, "")
    $X = StringReplace($X, $sDecimal, ".")
    $2X = $X * 2
    $HalfX = $X / 2
    $X = StringReplace(String($X), ".", $sDecimal)
    $2X = StringReplace(String($2X), ".", $sDecimal)
    $HalfX = StringReplace(String($HalfX), ".", $sDecimal)
    MsgBox(64, "Result", "Input:  " & $X & @CRLF & "Doubled:  " & $2X & @CRLF & "Halved:  " & $HalfX)
WEnd

Tested it with US-EN settings and 10,240.25 for input and it worked. Would be interested to know if anyone using other international settings have any trouble with it.

How do i implement this in my script so it works for every function?

Share this post


Link to post
Share on other sites

HI,

what about stripping all "." and "," from the input doing the calculation and then put them back?

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

Hi,

just a quick start:

; calc
#include<Array.au3>

$val =InputBox("Value", "")
$CommaPosition = StringInStr($val, ",", Default, -1)
$PointPosition = StringInStr($val, ".", Default, -1)
ConsoleWrite($PointPosition & " " & $CommaPosition)

If $PointPosition = 0 And $CommaPosition = 0 Then
    Dim $r = calc($val)
    _ArrayDisplay($r,"Result")
EndIf

If $PointPosition < $CommaPosition Then
    ConsoleWrite("1 " &$val)
    $val = StringReplace($val, ".", "")
        ConsoleWrite("2 " &$val)
    $val = StringReplace($val, ",", ".")
        ConsoleWrite("3 " &$val)
    Dim $r = calc($val)
    _ArrayDisplay($r,"Result")
EndIf

If $PointPosition > $CommaPosition Then
    ConsoleWrite("1 " &$val)
    $val = StringReplace($val, ",", "")
    ConsoleWrite("3 " &$val)
    Dim $r = calc($val)
    _ArrayDisplay($r,"Result")
EndIf

Func calc($value)
    Local $result[3] = [$value, $value*2, $value/2] 
    Return $result
EndFunc

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

That was basically what I was thinking could be done.

Input: 10,240.25 (changes to 10,240,25)

Doubled: 20,48

Halved: 5,12

same with 10.240,25

Regional setting sv (swedish)

I guess it's not counting regardless what the setting is. you have to see what the value is in the registry and translate accoring to that value. could be a tough cookie to crack, if you don't omit the decimal (as a decimal sign in sweden is a comma, in US it's a dot ?) using a different editbox or something. or if the 3rd char from the right is either a decimal or a dot , change it to the regional settings value of a decimal. And change every 4th value thereafter from the right to the value of thousand delimiter.

there must be an easier way...

What do you get for the reg values sDecimal and sThousands with the sv regional setting? The only way to get "Input: 10,240.25 (changes to 10,240,25)" is if you inappropriately used US-EN input with some other settings.

Let me clarify: The script I posted will convert numbers correctly formatted per the regional settings to what I am assuming are internal AutoIT standards (no thousands seperator and a dot for the decimal place). It does not convert from a different region to the locally set region. If you have sv regional settings, then your input should have been consistent with that. If sv regional setting means sDecimal is a comma and sThousands is a dot, then your input should have been "10.240,25" but that could not have resulted in a converted input of "10,240,25" because my script only removes the thousands seperator, not translates it. So, what are the actual values for sDecimal and sThousands in your registry? :)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Hi,

just a quick start:

; calc
#include<Array.au3>

$val =InputBox("Value", "")
$CommaPosition = StringInStr($val, ",", Default, -1)
$PointPosition = StringInStr($val, ".", Default, -1)
ConsoleWrite($PointPosition & " " & $CommaPosition)

If $PointPosition = 0 And $CommaPosition = 0 Then
    Dim $r = calc($val)
    _ArrayDisplay($r,"Result")
EndIf

If $PointPosition < $CommaPosition Then
    ConsoleWrite("1 " &$val)
    $val = StringReplace($val, ".", "")
        ConsoleWrite("2 " &$val)
    $val = StringReplace($val, ",", ".")
        ConsoleWrite("3 " &$val)
    Dim $r = calc($val)
    _ArrayDisplay($r,"Result")
EndIf

If $PointPosition > $CommaPosition Then
    ConsoleWrite("1 " &$val)
    $val = StringReplace($val, ",", "")
    ConsoleWrite("3 " &$val)
    Dim $r = calc($val)
    _ArrayDisplay($r,"Result")
EndIf

Func calc($value)
    Local $result[3] = [$value, $value*2, $value/2] 
    Return $result
EndFunc

So long,

Mega

That method makes assumptions about what is a thousands or decimal seperator, and also assumes the decimal point (whatever char it is) will be present. Would that work for the following values? (all US-EN examples) --

10240.25

10,240.25

102402.5

102405

102,405

102.405

1.02405

1,024.025

The trick is to use the registry setting to know what to look for, not assume the thousands seperator or decimal place are there, yet handle them correctly if they are.

Of course, this is all moot if I've just missed some basic straight-forward way that AutoIT "just works" with non-EN regional settings without all this manual conversion... :)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

That method makes assumptions about what is a thousands or decimal seperator, and also assumes the decimal point (whatever char it is) will be present. Would that work for the following values? (all US-EN examples) --

10240.25

10,240.25

102402.5

102405

102,405

102.405

1.02405

1,024.025

The trick is to use the registry setting to know what to look for, not assume the thousands seperator or decimal place are there, yet handle them correctly if they are.

Of course, this is all moot if I've just missed some basic straight-forward way that AutoIT "just works" with non-EN regional settings without all this manual conversion... :)

HI,

I think it works! :P

; calc
#include<Array.au3>
Global $calc[9] = ['', "10240.25", "10,240.25", "102402.5", "102405", "102,405", "102.405", "1.02405", "1,024.025"]

For $i = 1 To UBound($calc) - 1
    calc1($calc[$i])
Next

Func calc1($val)
    ;$val =InputBox("Value", "")
    $CommaPosition = StringInStr($val, ",", Default, -1)
    $PointPosition = StringInStr($val, ".", Default, -1)
    ConsoleWrite($PointPosition & " " & $CommaPosition)

    If $PointPosition = 0 And $CommaPosition = 0 Then
        Dim $r = calc($val)
        _ArrayDisplay($r, "Result")
    EndIf

    If $PointPosition < $CommaPosition Then
        ConsoleWrite("1 " & $val)
        $val = StringReplace($val, ".", "")
        ConsoleWrite("2 " & $val)
        $val = StringReplace($val, ",", ".")
        ConsoleWrite("3 " & $val)
        Dim $r = calc($val)
        _ArrayDisplay($r, "Result")
    EndIf

    If $PointPosition > $CommaPosition Then
        ConsoleWrite("1 " & $val)
        $val = StringReplace($val, ",", "")
        ConsoleWrite("3 " & $val)
        Dim $r = calc($val)
        _ArrayDisplay($r, "Result")
    EndIf
EndFunc   ;==>calc1

Func calc($value)
    Local $result[3] = [$value, $value * 2, $value / 2]
    Return $result
EndFunc   ;==>calc

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Share this post


Link to post
Share on other sites

HI,

I think it works! :)

; calc
#include<Array.au3>
Global $calc[9] = ['', "10240.25", "10,240.25", "102402.5", "102405", "102,405", "102.405", "1.02405", "1,024.025"]

For $i = 1 To UBound($calc) - 1
    calc1($calc[$i])
Next

Func calc1($val)
    ;$val =InputBox("Value", "")
    $CommaPosition = StringInStr($val, ",", Default, -1)
    $PointPosition = StringInStr($val, ".", Default, -1)
    ConsoleWrite($PointPosition & " " & $CommaPosition)

    If $PointPosition = 0 And $CommaPosition = 0 Then
        Dim $r = calc($val)
        _ArrayDisplay($r, "Result")
    EndIf

    If $PointPosition < $CommaPosition Then
        ConsoleWrite("1 " & $val)
        $val = StringReplace($val, ".", "")
        ConsoleWrite("2 " & $val)
        $val = StringReplace($val, ",", ".")
        ConsoleWrite("3 " & $val)
        Dim $r = calc($val)
        _ArrayDisplay($r, "Result")
    EndIf

    If $PointPosition > $CommaPosition Then
        ConsoleWrite("1 " & $val)
        $val = StringReplace($val, ",", "")
        ConsoleWrite("3 " & $val)
        Dim $r = calc($val)
        _ArrayDisplay($r, "Result")
    EndIf
EndFunc   ;==>calc1

Func calc($value)
    Local $result[3] = [$value, $value * 2, $value / 2]
    Return $result
EndFunc   ;==>calc

So long,

Mega

It's certainly very close (I like the way you did it). But the bad assumption is that whatever character is found will be a decimal point. So if the regional setting for sDecimal is either comma or period, then either of these get the right answer from your script:

123.456

123,456

But if the regional setting is US or some other where comma is a thousands seperator, then the second one should be read "one hundred twenty three thousand four hundred fifty six", and your script reads it as "one hundred twenty three point four five six". You still need to read from somewhere (i.e. sDecimal and sThousands in the registry) to see what to expect on the input.

:P


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Also, in the Gui you could have a seperate input for the decimal, that then added the two decimals latter, and in a Gui input you can disable all but number input, I don't know how, but I will post again when I find out

Hope I helped

Share this post


Link to post
Share on other sites

one other thing to test might be.

check if the third char from right is a decimal, if not strip all thousand,decimals and points from the text and divide by 100 (that way it will choose the thousand separator and decimal your system has... theoratically).

If the 3rd char is a decimal it will still work if you remove all points,decimals and spaces and divide by 100. (theoratically)

but then again, I've been wrong before :)


> there are 10 types of people in the world, those who understand binary and those who don't.

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Wouldn't it be simpler to just not allow the use of anything but ".", or even better, what if you set "," to be a hotkey for sending "." then if someone entered a "," it would be sent as a "." just an idea, that would be simple.

;Edited for Typos

Edited by joedoe

Share this post


Link to post
Share on other sites

Wouldn't it be simpler to just not allow the use of anything but ".", or even better, what if you set "," to be a hotkey for sending "." then if someone entered a "," it would be sent as a "." just an idea, that would be simple.

;Edited for Typos

These are the script lines you would need
;At start of script
HotKeySet(",", "PeriodSend")


;At end or with functions
Func PeriodSend()
    Send(".")
EndFunc

Share this post


Link to post
Share on other sites

HI,

nice idea, I thought the same before, but what if somebody copies the price and pastes it to the inputfield? :)

I think, it is very easy to build the func for one regional setting, but to fit every possibility there have to be some guidelines how to use it.

So long,

Mega


Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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