Moderators SmOke_N Posted February 24 Moderators Share Posted February 24 (edited) Well, it's in the notes... While listening to an audio book I got annoyed at the constant misreading of numbers. Example: 692,000 would be read as six hundred ninety two zero-zero-zero. It got me thinking, how difficult is it to read them out to an understandable value? See Zips for Examples AutCode is a part of my personal format library, not sure I'll be releasing it, but maybe. Edit: 02/25/2024 This is script breaking, I added more bloat (purposely) and added Spanish as a sub language. I'm not 100% sure if it's absolutely correct though lol. Same day: Fixed decimal issue and returning the not needed zero/cero at the end of 1200 etc Same day: Added some escape char code for ramdon delimiters being passed Edit: 02/26/2024 Added a Text to Number approach, seems to work on English. Fixed code for NumberToText... probably going to zip them, cuz my copy-paste-kungfu is evidently weak! Same day, fixed Spanish issue with y un mil being shown as y mil Edit: 02/27/2024 Added Text to Number approach for Spanish as well, update in zip as well as an example Update same day: had to fix some found issues with decimal, didn't realize I did case sensitive, and I'm to lazy to make it an option (as we're working with numbers and I don't feel like we should have case sensitivity). Updated same day: fixed some other language issues found in Spanish with something like "mil" only being sent to Text To Number. Added: _AutCode_TextNumberGetLanguage , it's just a simple way to get the language of the numbers you're sending... If I'm being honest, I don't see it being incredibly useful. At the moment, it's sending a string return of the language, I don't like this, so I may change it to what it should be in my opinion (to match $N2T_XXX vars). But I'm tired of playing with this thing atm. Edit: 03/01/2024 Added a database version, it's been nearly a decade since I played with databases, so it is definitely not marked for speed at the moment. Once I'm more proficient (again ), I'll probably update the query optimization and db performance... right now it's fairly vanilla... But hey, it works. See NumTextNumDB zip for this one. Zip has both x86/x64 sqlite3 dll from official site (feel free to download your own if you don't want to do a checksum or don't trust mine) and the .db3 filled with the query data. Edit: 03/03/2024 Fixed: English and Spanish only returning blank string when "0", "00", or "000" only is passed Fixed: English and Spanish returning zero [thousands,millions] when something like 100,000,000 is passed Added: German and French -- Removed non-db version that I am no longer updating because it has less features and the same features are in the db version. NumTextNumDB_03032024(1).zip Edited March 4 by SmOke_N Skeletor, argumentum, ioa747 and 1 other 4 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 More sharing options...
argumentum Posted February 24 Share Posted February 24 BuildIt("Make 692000, and be happy.") ; didn't read the book =P Func BuildIt($sStr) Local $aArray = StringSplit(StringReplace(StringStripWS($sStr, 7), ",", " , "), " ") $sStr = "" For $n = 1 To $aArray[0] If Number($aArray[$n]) == $aArray[$n] Then $sStr &= StringStripWS(_AutCode_NumberToText($aArray[$n]), 7) & " " Else $sStr &= $aArray[$n] & " " EndIf Next $sStr = StringReplace($sStr, " , ", ",") ConsoleWrite('+++ ' & $sStr & @CRLF) SayIt($sStr) EndFunc ;==>BuildIt Func SayIt($sStr = "Replace with that you wanna say.") Local Static $oSapi = ObjCreate("Sapi.SPVoice") $oSapi.Speak($sStr) EndFunc ;==>SayIt Look. A book reader Thanks for sharing. SmOke_N 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Somerset Posted February 24 Share Posted February 24 I remember having to write out basically a phonetic dictionary for a reader awhile ago, and i understand the annoyance. Thanks for the contribution. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 25 Author Moderators Share Posted February 25 See first post, Spanish added, keep in mind, it's script breaking. 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 More sharing options...
LAteNightSpecial Posted February 25 Share Posted February 25 expandcollapse popup#include-once #include <StringConstants.au3> Global Const $N2T_LANG_ENGLISH = 0 Global Const $N2T_LANG_SPANISH = 1 Func NumberToText($number, $language = $N2T_LANG_ENGLISH) If $number = 0 Then Return "zero" Local $negative = False If $number < 0 Then $negative = True $number = Abs($number) EndIf Local $integerPart = Int($number) Local $decimalPart = $number - $integerPart Local $integerText = NumberToText_Group($integerPart, $language) Local $decimalText = "" If $decimalPart > 0 Then $decimalText = " point " & NumberToText_Group($decimalPart * 100, $language) EndIf If $negative Then $integerText = "negative " & $integerText Return $integerText & $decimalText EndFunc Func NumberToText_Group($number, $language) ; Define language-specific rules Local $ones, $tens, $teens, $thousands Switch $language Case $N2T_LANG_ENGLISH $ones = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] $tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"] $teens = ["", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"] $thousands = ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion"] Case $N2T_LANG_SPANISH $ones = ["", "uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve"] $tens = ["", "", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa"] $teens = ["", "once", "doce", "trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve"] $thousands = ["", "mil", "millón", "mil millones", "billón", "mil billones", "trillón", "mil trillones"] EndSwitch Local $text = "" Local $group = 0 Do Local $num = Mod($number, 1000) If $num > 0 Then Local $hundreds = Int($num / 100) Local $tensAndOnes = Mod($num, 100) Local $groupText = "" If $hundreds > 0 Then $groupText &= $ones[$hundreds] & " hundred" EndIf If $tensAndOnes > 0 Then If $tensAndOnes < 10 Then $groupText &= " " & $ones[$tensAndOnes] ElseIf $tensAndOnes < 20 Then $groupText &= " " & $teens[$tensAndOnes - 10] Else Local $tensDigit = Int($tensAndOnes / 10) Local $onesDigit = Mod($tensAndOnes, 10) $groupText &= " " & $tens[$tensDigit] If $onesDigit > 0 Then $groupText &= "-" & $ones[$onesDigit] EndIf EndIf $groupText &= " " & $thousands[$group] $text = $groupText & " " & $text EndIf $group += 1 $number = Int($number / 1000) Until $number = 0 Return StringTrimRight($text, 1) EndFunc Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 25 Author Moderators Share Posted February 25 Neat, good luck with that logic on Spanish lol, I had it pretty simple too at first. 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 More sharing options...
LAteNightSpecial Posted February 25 Share Posted February 25 4 minutes ago, SmOke_N said: Neat, good luck with that logic on Spanish lol, I had it pretty simple too at first. Touché, La programmation est comme une recette délicate; tester est l'assaisonnement essentiel pour un plat parfait expandcollapse popup#include-once #include <MsgBoxConstants.au3> Global Const $N2T_LANG_ENGLISH = 0 Global Const $N2T_LANG_SPANISH = 1 Func NumberToText($number, $language = $N2T_LANG_ENGLISH) If $number = 0 Then Return "zero" Local $negative = False If $number < 0 Then $negative = True $number = Abs($number) EndIf Local $integerPart = Int($number) Local $decimalPart = $number - $integerPart Local $integerText = NumberToText_Group($integerPart, $language) Local $decimalText = "" If $decimalPart > 0 Then $decimalText = " point " & NumberToText_Group($decimalPart * 100, $language) EndIf If $negative Then $integerText = "negative " & $integerText Return $integerText & $decimalText EndFunc Func NumberToText_Group($number, $language) Local $ones, $tens, $teens, $thousands Switch $language Case $N2T_LANG_ENGLISH $ones = ["", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] $tens = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"] $teens = ["", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"] $thousands = ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion"] Case $N2T_LANG_SPANISH ; Modified ones array to handle "uno" to "un" transformation $ones = ["", "un/uno", "dos", "tres", "cuatro", "cinco", "seis", "siete", "ocho", "nueve"] $tens = ["", "", "veinte", "treinta", "cuarenta", "cincuenta", "sesenta", "setenta", "ochenta", "noventa"] $teens = ["", "once", "doce", "trece", "catorce", "quince", "dieciséis", "diecisiete", "dieciocho", "diecinueve"] $thousands = ["", "mil", "millón", "mil millones", "billón", "mil billones", "trillón", "mil trillones"] EndSwitch Local $text = "" Local $group = 0 Do Local $num = Mod($number, 1000) If $num > 0 Then Local $hundreds = Int($num / 100) Local $tensAndOnes = Mod($num, 100) Local $groupText = "" If $hundreds > 0 Then ; Handle "ciento" to "cien" transformation If $hundreds = 1 And $tensAndOnes = 0 Then $groupText &= "cien" Else $groupText &= $ones[$hundreds] & "cientos" EndIf EndIf If $tensAndOnes > 0 Then If $tensAndOnes < 10 Then ; Split "un/uno" to handle "uno" to "un" transformation $groupText &= " " & StringSplit($ones[$tensAndOnes], "/")[1] ElseIf $tensAndOnes < 20 Then $groupText &= " " & $teens[$tensAndOnes - 10] Else Local $tensDigit = Int($tensAndOnes / 10) Local $onesDigit = Mod($tensAndOnes, 10) $groupText &= " " & $tens[$tensDigit] If $onesDigit > 0 Then $groupText &= " y " & $ones[$onesDigit] EndIf EndIf $groupText &= " " & $thousands[$group] $text = $groupText & " " & $text EndIf $group += 1 $number = Int($number / 1000) Until $number = 0 Return StringTrimRight($text, 1) EndFunc ; Example usage Local $numbersToConvert[3] = [123, -456.78, 987654321] For $number In $numbersToConvert ; Convert to English Local $textEnglish = NumberToText($number, $N2T_LANG_ENGLISH) MsgBox($MB_OK, "English", $number & " in English: " & $textEnglish) ; Convert to Spanish Local $textSpanish = NumberToText($number, $N2T_LANG_SPANISH) MsgBox($MB_OK, "Spanish", $number & " in Spanish: " & $textSpanish) Next Other Potential Considerations Gender Agreement: You might want to explore ways to potentially handle gender agreement for other numbers if that's a requirement for your use cases. This could involve parameter additions to the function to indicate gender or agreement logic within the NumberToText_Group. Complex Plurals: While Spanish plurals might not necessitate changes in this thousands array, keeping them in mind is essential if you aim to translate larger numbers or different word types. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 25 Author Moderators Share Posted February 25 I thought about the gender part too... tbh, I'm probably never going to use this... it was just something that irritated me enough to do something. BTW, what version of AutoIt are you running that it works in? I ran it and it did nothing but error until I categorized your arrays in the NumberToText_Group() func (and you're missing "ten" and "diez") You're pretty sharp though, you certainly remind me of someone from the past lol... thanks for joining and commenting. LAteNightSpecial 1 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 More sharing options...
LAteNightSpecial Posted February 25 Share Posted February 25 8 minutes ago, SmOke_N said: I thought about the gender part too... tbh, I'm probably never going to use this... it was just something that irritated me enough to do something. BTW, what version of AutoIt are you running that it works in? I ran it and it did nothing but error until I categorized your arrays in the NumberToText_Group() func (and you're missing "ten" and "diez") You're pretty sharp though, you certainly remind me of someone from the past lol... thanks for joining and commenting. A perro entre ein居酒屋 e bibit太多了 vodka. Kisha מתגלגל على फर्श 웃으며! Creating a virtual environment in x64 assembly to run AutoIt code on a Linux machine is an incredibly complex task, and it's not a straightforward process. Additionally, running AutoIt code on Linux directly is not supported because AutoIt is designed for Windows environments. As for building a virtual environment in x64 assembly, this would involve creating a complete runtime environment that emulates the behavior of a Windows system, including system calls, memory management, and more. This is an incredibly challenging task that typically requires a deep understanding of both x64 assembly language and operating system internals. Thank you for the kind words SmOke_N, but I do not think we have ever been properly introduced. Thank you for allowing me to contribute to your community. It is always a pleasure pushing the boundaries of what is and what can be. However, patience and determination can accomplish many tasks. We never throw stones in glass houses, as we might get cut by the sharp shards. Respect ~ raphacp and SmOke_N 1 1 Link to comment Share on other sites More sharing options...
Danyfirex Posted February 26 Share Posted February 26 I think is not working with decimals. I tried with this: @SmOke_N MsgBox(0,"",_AutCode_NumberToText("456.78",True,"","",$N2T_LANGSPANISH)) Result: cuatrocientos Cincuenta y seissetenta y ocho I think it should be: Cuatrocientos cincuenta y seis con setenta y ocho MsgBox(0,"",_AutCode_NumberToText("456.78",True,"","",$N2T_LANGENGLISH)) Result: four hundred Fifty sixseventy eight I think it should be: Four Hundred Fifty Six Point Seventy Eight also 1200 is showing wrong result en both languages. @LAteNightSpecial any of your code is working properly even with simple 1001 or 1200 Saludos SmOke_N 1 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
LAteNightSpecial Posted February 26 Share Posted February 26 34 minutes ago, Danyfirex said: I think is not working with decimals. I tried with this: @SmOke_N MsgBox(0,"",_AutCode_NumberToText("456.78",True,"","",$N2T_LANGSPANISH)) Result: cuatrocientos Cincuenta y seissetenta y ocho I think it should be: Cuatrocientos cincuenta y seis con setenta y ocho MsgBox(0,"",_AutCode_NumberToText("456.78",True,"","",$N2T_LANGENGLISH)) Result: four hundred Fifty sixseventy eight I think it should be: Four Hundred Fifty Six Point Seventy Eight also 1200 is showing wrong result en both languages. @LAteNightSpecial any of your code is working properly even with simple 1001 or 1200 Saludos You're absolutely right! It seems there's a bug in how both the original and revised versions of the script handle decimals. Let's break down the issues and how to fix them. Problem Analysis Decimal Part: The current code isn't designed to correctly translate the decimal portion. It seems to be treating the decimal portion as another whole number. 1200 Case: The reason 1200 is giving incorrect results is likely an off-by-one error in the way the three-digit groups are processed. Fixing the Script Here's how we can modify the NumberToText function to address these: Func NumberToText($number, $language = $N2T_LANG_ENGLISH) ; ... (Existing code for negative handling and integer part) ... Local $decimalPart = $number - $integerPart Local $integerText = NumberToText_Group($integerPart, $language) Local $decimalText = "" If $decimalPart > 0 Then $decimalParts = StringSplit($decimalPart, ".")[2] ; Get only the digits after the decimal point If StringLen($decimalParts) > 2 Then ; Limit to two decimal places $decimalParts = StringLeft($decimalParts, 2) EndIf $decimalText = " con " & NumberToText_Group(Int($decimalParts), $language) EndIf If $negative Then $integerText = "negative " & $integerText Return $integerText & $decimalText EndFunc Changes Decimal Isolation: We use StringSplit to get only the part of the number after the decimal point and limit it to two places. Decimal Translation: We then pass the decimal part (as an integer to remove leading zeroes) to the NumberToText_Group function for conversion. "con": In Spanish, we use "con" to connect the whole and decimal parts of the number. Note: You might need to make adjustments to the NumberToText_Group for the 1200 case if that's due to array indexing. Testing Make sure to re-run your tests with the provided numbers (456.78, 1200) after integrating this fix! raphacp 1 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 26 Author Moderators Share Posted February 26 44 minutes ago, Danyfirex said: I think is not working with decimals. I tried with this: @SmOke_N MsgBox(0,"",_AutCode_NumberToText("456.78",True,"","",$N2T_LANGSPANISH)) Result: cuatrocientos Cincuenta y seissetenta y ocho I think it should be: Cuatrocientos cincuenta y seis con setenta y ocho MsgBox(0,"",_AutCode_NumberToText("456.78",True,"","",$N2T_LANGENGLISH)) Result: four hundred Fifty sixseventy eight I think it should be: Four Hundred Fifty Six Point Seventy Eight also 1200 is showing wrong result en both languages. @LAteNightSpecial any of your code is working properly even with simple 1001 or 1200 Saludos Honestly... that's definitely my fault, I don't think I even tested the new method with decimal... ugh. Thanks for pointing it out, I'll have a look later. 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 More sharing options...
Moderators SmOke_N Posted February 26 Author Moderators Share Posted February 26 1 hour ago, Danyfirex said: I think is not working with decimals. I tried with this: @SmOke_N MsgBox(0,"",_AutCode_NumberToText("456.78",True,"","",$N2T_LANGSPANISH)) Result: cuatrocientos Cincuenta y seissetenta y ocho I think it should be: Cuatrocientos cincuenta y seis con setenta y ocho MsgBox(0,"",_AutCode_NumberToText("456.78",True,"","",$N2T_LANGENGLISH)) Result: four hundred Fifty sixseventy eight I think it should be: Four Hundred Fifty Six Point Seventy Eight also 1200 is showing wrong result en both languages. @LAteNightSpecial any of your code is working properly even with simple 1001 or 1200 Saludos I fixed the 1200 issue... but the decimal issue is because you didn't tell it what to use in the 4th parameter, you used "" rather than " Point " or " Punto ". See this example after you get the corrected code: Global $gsStr = "1200" ConsoleWrite($gsStr & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, False, "", "", $N2T_LANGENGLISH) & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, False, "", "", $N2T_LANGSPANISH) & @CRLF) $gsStr = "456.78" ConsoleWrite($gsStr & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, True, "", " Point ", $N2T_LANGENGLISH) & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, True, "", " Punto ", $N2T_LANGSPANISH) & @CRLF) Danyfirex 1 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 More sharing options...
LAteNightSpecial Posted February 26 Share Posted February 26 (edited) 33 minutes ago, SmOke_N said: I fixed the 1200 issue... but the decimal issue is because you didn't tell it what to use in the 4th parameter, you used "" rather than " Point " or " Punto ". See this example after you get the corrected code: Global $gsStr = "1200" ConsoleWrite($gsStr & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, False, "", "", $N2T_LANGENGLISH) & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, False, "", "", $N2T_LANGSPANISH) & @CRLF) $gsStr = "456.78" ConsoleWrite($gsStr & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, True, "", " Point ", $N2T_LANGENGLISH) & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, True, "", " Punto ", $N2T_LANGSPANISH) & @CRLF) Thanks to your sharp eye, here's the complete breakdown of your example code: Explanation Global String: You define $gsStr to hold the number strings for testing. 1200 Tests: You call _AutCode_NumberToText with $gsStr (1200) and the appropriate language constants, demonstrating that the 1200 issue has been resolved. 456.78 Tests: You update $gsStr and then call _AutCode_NumberToText again, this time including the " Point " and " Punto " separators to correctly format the decimal output. Excellent catch! This fix ensures a much more accurate and user-friendly number-to-text translation in both English and Spanish. Considerations: Invalid Input: The current script doesn't gracefully handle non-numeric input or numbers that are too large for the defined number arrays. Adding checks and returning appropriate error messages would make it more robust. Array Bounds: Consider verifying that numbers fit within the bounds of the ones, tens, thousands, etc. arrays to prevent potential errors. Great Job SmOke_N! Who cares if nobody wants to use our codes, or even if we want to use them. We find something that does not work the way we would like it to, thus we make it work the way we want it to. In the true spirit of Duct-Tape and a 9-Volt Battery just to get the car started in the dead of winter! 🤗 Edited February 26 by LAteNightSpecial raphacp 1 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 26 Author Moderators Share Posted February 26 53 minutes ago, LAteNightSpecial said: Considerations: Invalid Input: The current script doesn't gracefully handle non-numeric input or numbers that are too large for the defined number arrays. Adding checks and returning appropriate error messages would make it more robust. Array Bounds: Consider verifying that numbers fit within the bounds of the ones, tens, thousands, etc. arrays to prevent potential errors. Bounds are caught ; Is the group of numbers larger than sextillion (current largest amount because spanish was hard!) If $iUB > $iNumTypeUB Then As far as input, you're right I think... I didn't think much about it if at all. Which brings up another thing about passing delim, if it's not an escaped delim it would cause issues since it uses RegEx... so good catch 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 More sharing options...
LAteNightSpecial Posted February 26 Share Posted February 26 (edited) 35 minutes ago, SmOke_N said: Bounds are caught ; Is the group of numbers larger than sextillion (current largest amount because spanish was hard!) If $iUB > $iNumTypeUB Then As far as input, you're right I think... I didn't think much about it if at all. Which brings up another thing about passing delim, if it's not an escaped delim it would cause issues since it uses RegEx... so good catch Invalid Input Handling: We'll integrate string validation using StringRegExp to ensure the input string contains only valid characters (digits, the decimal point, and potentially the negative sign). Additionally, we'll consider setting a reasonable maximum input size to prevent potential memory issues or unexpected behavior. Escaped Delimiters: We'll introduce a helper function _EscapeDelimiters to escape any special regular expression characters within the user-provided delimiter. Then, we'll modify function calls to utilize this function and ensure that delimiters do not interfere with internal regular expressions. Here's how we can implement these enhancements: expandcollapse popup; Validate input string Func _ValidateInput($number) Local $validNumberPattern = "^\-?[0-9]+(\.[0-9]+)?$" If Not StringRegExp($number, $validNumberPattern) Then MsgBox(0, "Error", "Invalid number format. Please use only digits, a decimal point, and an optional negative sign.") Return False EndIf If StringLen($number) > 1000 Then ; Set a reasonable maximum input size MsgBox(0, "Error", "Input number exceeds maximum length.") Return False EndIf Return True EndFunc ; Escape special regular expression characters in delimiter Func _EscapeDelimiters($delim) $delim = StringRegExpReplace($delim, "([\[\]\{\}\(\)\*\+\?\.\\\^\$])", "\\$1") Return $delim EndFunc ; Main function with enhancements Func EnhancedFunction($number, $sRetDelim) ; Validate input If Not _ValidateInput($number) Then Return False EndIf ; Escape user-provided delimiter Local $escapedDelim = _EscapeDelimiters($sRetDelim) ; Call the main function with escaped delimiter $sRet = _AutCode_NumberToText($aInt, $escapedDelim, $iLang) Return $sRet EndFunc By incorporating these changes, we ensure better input validation and handle potential issues with delimiters more robustly, improving the overall reliability of the script. Overall These refinements significantly bolster the robustness and user-friendliness of your script! Testing Tip: Prepare a set of test cases that include: Valid numbers of various sizes Invalid inputs with non-numeric characters Excessively long numbers Different delimiters with and without special characters Run these tests to verify that your enhanced script handles them gracefully. Here's how we can modify the _TextNumberGerman function to support multiple languages (But You Already Know This, Hola) expandcollapse popupFunc _TextNumber($nNumber, $iLanguage = "English", $iDecimalPlaces = Default) Local $aLanguages[3] = ["English", "Spanish", "German"] ; Add more languages as needed ; Define language-specific arrays Local $aLanguageArrays[3][8] ; Adjust the size according to the number of languages and the size of the arrays ; English language arrays $aLanguageArrays[0][0] = ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion"] $aLanguageArrays[0][1] = ["", "mil", "millón", "mil millones", "billón", "mil billones", "trillón", "mil trillones"] $aLanguageArrays[0][2] = ["", "tausend", "Million", "Milliarde", "Billion", "Billiarde", "Trillion", "Trilliarde"] ; Spanish language arrays $aLanguageArrays[1][0] = ["", "mil", "millón", "mil millones", "billón", "mil billones", "trillón", "mil trillones"] $aLanguageArrays[1][1] = ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion"] $aLanguageArrays[1][2] = ["", "tausend", "Million", "Milliarde", "Billion", "Billiarde", "Trillion", "Trilliarde"] ; German language arrays $aLanguageArrays[2][0] = ["", "tausend", "Million", "Milliarde", "Billion", "Billiarde", "Trillion", "Trilliarde"] $aLanguageArrays[2][1] = ["", "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion"] $aLanguageArrays[2][2] = ["", "mil", "millón", "mil millones", "billón", "mil billones", "trillón", "mil trillones"] Local $aLanguage = $aLanguageArrays[0] ; Default to English For $i = 0 To UBound($aLanguages) - 1 If StringCompare($iLanguage, $aLanguages[$i], 0) = 0 Then $aLanguage = $aLanguageArrays[$i] ExitLoop EndIf Next ; Use the selected language arrays for processing Local $aSingular = $aLanguage[0] Local $aPlural = $aLanguage[1] Local $aNullEins = $aLanguage[2] Local $aKleiner20 = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", _ "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"] Local $aZehner = ["twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"] Local $aDezimal = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"] ; The rest of the function remains the same, using the selected language arrays EndFunc In this modified version of the function: We define language-specific arrays for each supported language, containing translations for words such as "thousand", "million", etc. The function takes an additional parameter $iLanguage to specify the language. It defaults to English. Inside the function, we select the appropriate language arrays based on the input language. The rest of the function remains unchanged, utilizing the selected language arrays for processing the number. Further Refinements (Optional) Data Externalization: For large-scale projects, you might consider storing the language word arrays in a configuration file (XML, JSON, INI) to make updates easier without modifying code. Language Code Standardization: Use standard language codes (e.g., "en", "es", "de") for consistency. P.S. This is fun! I haven't been able to feel this young for a long long time. I still can't remember when they dropped the second PERIOD from the Mandela Effect. Anyways, again thank you! Let's keep working! Edited February 26 by LAteNightSpecial raphacp 1 Link to comment Share on other sites More sharing options...
Danyfirex Posted February 26 Share Posted February 26 @SmOke_N $gsStr = "456.78" ConsoleWrite($gsStr & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, True, "", " Point ", $N2T_LANGENGLISH) & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, True, "", " Punto ", $N2T_LANGSPANISH) & @CRLF) that's not working. console is empty. Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 26 Author Moderators Share Posted February 26 (edited) 10 minutes ago, Danyfirex said: @SmOke_N $gsStr = "456.78" ConsoleWrite($gsStr & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, True, "", " Point ", $N2T_LANGENGLISH) & @CRLF) ConsoleWrite( _ _AutCode_NumberToText($gsStr, True, "", " Punto ", $N2T_LANGSPANISH) & @CRLF) that's not working. console is empty. Hmm... Quote 456.78 four hundred fifty six Point seventy eight cuatrocientos cincuenta y seis Punto setenta y ocho That's my output running your code, are you running the newest one? I also added a text to number (for english) Edit: Sorry Danny, I think I messed up something when I added the new code. I just updated it with code I know is working. Edited February 26 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 More sharing options...
Danyfirex Posted February 26 Share Posted February 26 Yes the code I'm using is the one in the top of the thread. but I returns nothing. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 26 Author Moderators Share Posted February 26 13 minutes ago, Danyfirex said: Yes the code I'm using is the one in the top of the thread. but I returns nothing. Saludos I've no idea lol, it's running for me. I zipped them, would you mind trying the zip? I tested both examples. Thanks for the feedback... 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 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