drunkfux Posted September 20, 2006 Share Posted September 20, 2006 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: expandcollapse popup#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 Link to comment Share on other sites More sharing options...
logi Posted September 20, 2006 Share Posted September 20, 2006 you could try something like: $prijs1 = StringReplace($prijs1, ",", ".") I will look into it. Link to comment Share on other sites More sharing options...
drunkfux Posted September 20, 2006 Author Share Posted September 20, 2006 (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 expandcollapse popup#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 September 20, 2006 by drunkfux Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 20, 2006 Share Posted September 20, 2006 (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 September 20, 2006 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 Link to comment Share on other sites More sharing options...
drunkfux Posted September 21, 2006 Author Share Posted September 21, 2006 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 Link to comment Share on other sites More sharing options...
jinxter Posted September 21, 2006 Share Posted September 21, 2006 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. Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 21, 2006 Share Posted September 21, 2006 (edited) Tried your test script with 10.000,00 as input.. results aren't good 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. Edited September 21, 2006 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 Link to comment Share on other sites More sharing options...
jinxter Posted September 21, 2006 Share Posted September 21, 2006 (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 September 21, 2006 by jinxter > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
drunkfux Posted September 26, 2006 Author Share Posted September 26, 2006 $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? Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 26, 2006 Share Posted September 26, 2006 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 Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 26, 2006 Share Posted September 26, 2006 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 26, 2006 Share Posted September 26, 2006 (edited) That was basically what I was thinking could be done.Input: 10,240.25 (changes to 10,240,25) Doubled: 20,48Halved: 5,12same with 10.240,25Regional 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 September 26, 2006 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 26, 2006 Share Posted September 26, 2006 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 Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 26, 2006 Share Posted September 26, 2006 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! expandcollapse popup; 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 Link to comment Share on other sites More sharing options...
PsaltyDS Posted September 26, 2006 Share Posted September 26, 2006 HI, I think it works! expandcollapse popup; 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. 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 Link to comment Share on other sites More sharing options...
joedoe Posted September 26, 2006 Share Posted September 26, 2006 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 Link to comment Share on other sites More sharing options...
jinxter Posted September 27, 2006 Share Posted September 27, 2006 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. Link to comment Share on other sites More sharing options...
joedoe Posted September 28, 2006 Share Posted September 28, 2006 (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 September 28, 2006 by joedoe Link to comment Share on other sites More sharing options...
joedoe Posted September 28, 2006 Share Posted September 28, 2006 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 Link to comment Share on other sites More sharing options...
Xenobiologist Posted September 28, 2006 Share Posted September 28, 2006 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now