Deye Posted June 21, 2018 Share Posted June 21, 2018 (edited) Convert long strings (up to 3003) digits to words (Online script) Or Convert large numbers (wordings) back into digits, which is the main function for this example expandcollapse popup#include <ie.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $aArray[7][11] = [['', 'on', 'tw', 'th', 'fo', 'fi', 'si', 'se', 'ei', 'ni'], _ ['', 'ele', 'tw', 'th', 'fo', 'fi', 'si', 'se', 'ei', 'ni'], _ ['', 'te', 'tw', 'th', 'fo', 'fi', 'si', 'se', 'ei', 'ni'], _ ['hu', 'th', 'm', 'b', 'tr', 'qua', 'qui', 'x', 'se', 'oc', 'no'], _ ['', '', 'un', 'duo', 'tr', 'qua', 'qui', 'x', 'sep', 'oc'], _ ['', 'deci', 'vi', 'tri', 'quadra', 'quinqua', 'sexa', 'septu', 'octogin', 'nona', 'nt'], _ ['', 'centi', 'duce', 'trece', 'quadrin', 'quingen', 'sesce', 'septin', 'octin', 'nong']], $oIE, $hControl $hGui = GUICreate("Diget <=> Words (Converter)", 785, 400, -1, -1, $WS_MAXIMIZEBOX) GUICtrlSetResizing(-1, $GUI_DOCKAUTO) $idInput = GUICtrlCreateEdit("", 10, 10, 760, 310, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_VSCROLL)) GUICtrlSetFont(-1, 13) $B_Convert = GUICtrlCreateButton("Convert", 10, 330, 60, 30) $B_copy = GUICtrlCreateButton("Clip", 90, 330, 60, 30) $B_random = GUICtrlCreateButton("Random >> ", 180, 330, 90, 30) $B_Compair = GUICtrlCreateButton(" << Test Compair", 280, 330, 130, 30) $s_label = GUICtrlCreateLabel("", 12, 220, 740, 50) GUICtrlSetResizing(-1, $GUI_DOCKSIZE) GUISetBkColor(0x677791) GUICtrlSetFont(-1, 11, 100) GUICtrlSetColor(-1, 0xffffff) GUISetState(@SW_SHOW) GUICtrlSetData($idInput, "") $oIE = _IECreate("https://lingojam.com/NumbersToWords", '', 0) Global $hWnd = _IEPropertyGet($oIE, "hwnd"), $oSubmit = _IEGetObjById($oIE, "english-text"), $oTextLabel = _IEGetObjById($oIE, "ghetto-text") $hControl = ControlGetHandle($hWnd, "", "Internet Explorer_Server1") Local $aAccelKeys[2][2] = [["{F5}", $B_Convert], ["{Enter}", $B_Convert]] GUISetAccelerators($aAccelKeys) Local $iRandom, $sString, $LenS, $buisy Global $LenW While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE _IEQuit($oIE) Exit Case $B_Compair $sString = GUICtrlRead($idInput) If StringIsAlNum($sString) Then GUICtrlSetData($idInput, " Loading ...") $sString = DigitsToWords($sString) GUICtrlSetData($idInput, $sString) If $iRandom = NumWordsToDigits(GUICtrlRead($idInput)) Then GUICtrlSetData($s_label, " Success: The recorded random number which is " & $LenW & " ( " & $LenS & " ) digit long" & @CRLF & " Is matching the returned number from NumWordsToDigits() using the displayed words -parameter.") GUICtrlSetState($s_label, $GUI_show) EndIf Else GUICtrlSetData($s_label, @CRLF & " To continue first use the (Random >>) button and generate a new random number") EndIf Case $B_random GUICtrlSetState($s_label, $GUI_HIDE) GUICtrlSetData($idInput, " Loading ...") $iRandom = Upto_3003() $LenS = StringLen($iRandom) $LenW = DigitsToWords($LenS) GUICtrlSetData($idInput, $iRandom) Case $B_copy ClipPut(GUICtrlRead($idInput)) GUICtrlSetState($idInput, $GUI_FOCUS) Case $B_Convert GUICtrlSetState($s_label, $GUI_HIDE) $sString = StringStripWS(GUICtrlRead($idInput), 8) If StringIsDigit($sString) Then GUICtrlSetData($idInput, $sString) If StringLen(GUICtrlRead($idInput)) > 3003 Then MsgBox(0, '', "Can go only up to 3003 digits at this time ..") ContinueLoop EndIf GUICtrlSetData($idInput, " Loading ...") GUICtrlSetData($idInput, DigitsToWords($sString)) Else GUICtrlSetData($idInput, NumWordsToDigits(GUICtrlRead($idInput))) EndIf WinActivate($hGui, "") EndSwitch Sleep(5) WEnd Func Upto_3003() Local $iNumber = Random(1, 9, 1) For $count = 1 To Random(1, 3002, 1) $iNumber &= Random(0, 9, 1) Next Return $iNumber EndFunc Func NumWordsToDigits($sParse) If StringInStr($sParse, "zero") Then Return 0 Local $a, $istart, $iEnd, $ibump, $i, $iRet, $sTest, $iDiv, $iP_Div, $iN_Div, $aNum = StringSplit(StringStripWS(StringReplace(StringReplace(StringReplace($sParse, " and", "", 0), "-", " ", 0), ",", " ", 0), 6), " ", 1) For $1 = $aNum[0] To 0 Step -1 If StringInStr($aNum[$1], "drag") Then $aNum[$1] = (StringInStr($aNum[$1], "quadrag") = 0 ? StringReplace($aNum[$1], "drag", "quadrag") : $aNum[$1]) EndIf If $1 = 0 Then $iRet = $i & (_L($iRet, '>', $iN_Div) ? _tL($iP_Div & $iN_Div, $iRet) : _tL($iN_Div, $iRet)) & $iRet Return $iRet EndIf $a = Execute(StringRegExpReplace($aNum[$1], "^.*?(?:(deci|gin|gen|cen)|(elv|ele|een)|(^ten$|ty)|(hun|tho|ion)).*", "('$1'=''?0:4)+('$2'=''?0:1)+('$3'=''?0:2)+('$4'=''?0:3)")) If Not $a Then $a = 0 $istart = 0 $iEnd = 10 $ibump = "" If $a = 4 Then For $2 = 0 To 10 $ibump = $2 $pos = StringInStr($aNum[$1], $aArray[5][$2]) If $pos Then For $c = 10 To 0 Step -1 If StringInStr($aNum[$1], $aArray[6][$c]) Then If $2 = 10 Then $ibump = $c * $ibump If StringInStr($aNum[$1], $aArray[6][$c]) = 1 Then $pos = 1 Else If StringInStr($aNum[$1], "quinquadrin") Then $pos = 0 $ibump = 40 ExitLoop EndIf $ibump = $c & $2 EndIf ExitLoop EndIf Next If $pos = 1 Then $istart = 1 ExitLoop ElseIf StringInStr($aNum[$1], "nove") Then $ibump += 1 $istart = 0 ExitLoop Else $istart = (StringInStr($aNum[$1], 'sept') = 1 ? 8 : (StringInStr($aNum[$1], 'se') = 1 ? 7 : 2)) If $istart <> 2 Then ExitLoop For $U = 2 To 9 If StringInStr($aNum[$1], $aArray[4][$U], 0, 1, 1) = 1 Then $istart = $U ExitLoop 2 EndIf Next EndIf EndIf Next $iEnd = $istart EndIf For $b = $istart To $iEnd If $istart = $iEnd Or StringInStr($aNum[$1], $aArray[$a][$b]) Then Switch $a Case 0 $i = $b Case 1 $i = 1 & $b Case 2 If $i Then $i = $b & $i Else $i = $b & 0 EndIf Case 3, 4 $iN_Div = "" If $b > 1 Or $a = 4 Then For $k = ($a = 4 ? $ibump & $b : $b) To 1 Step -1 $iN_Div &= "000" Next Else $iN_Div = ($b = 1 ? "000" : "00") EndIf If $iDiv Then If $i Then $iRet = ($sTest <> "" ? $i & $sTest : (_L($iRet, '-', $iDiv & $iP_Div) = -1 ? _tL($iN_Div, "00" & $iRet) & $i & 0 : _tL($iN_Div, $i & $iRet) & $i)) & $iRet Else $iRet = _tL($iDiv, $iRet) & $iN_Div & $iRet EndIf Else $iRet = $i EndIf $sTest = _tL($iN_Div, $iRet) $iP_Div = $iDiv $iDiv = $iN_Div $i = "" EndSwitch ExitLoop 1 EndIf Next Next EndFunc Func _L($a = "", $Op = "", $b = "") Local $bReturn = StringLen($a) - StringLen($b) Return ($Op = "-" ? $bReturn : ($Op = ">" ? $bReturn > 0 : $bReturn >= 0)) EndFunc ;==>_L Func _tL($a = "", $b = "") Return StringTrimLeft($a, StringLen($b)) EndFunc Func DigitsToWords($iNum = "") If _IEFormElementGetValue($oSubmit) = $iNum Then Return $oTextLabel.innerText Local $sWords, $stmp = "" _IEFormElementSetValue($oSubmit, StringTrimRight($iNum, 1)) _IEFormElementSetValue($oTextLabel, "") ControlSend($hWnd, "", $hControl, StringRight($iNum, 1)) While Sleep(100) If StringInStr($oTextLabel.innerText, "And Words") Then ContinueLoop If $stmp <> $oTextLabel.innerText Then $stmp = $oTextLabel.innerText ContinueLoop EndIf Return $stmp WEnd Return "Something went wrong" EndFunc Edited June 30, 2018 by Deye Cleaned the interface Link to comment Share on other sites More sharing options...
Deye Posted June 21, 2018 Author Share Posted June 21, 2018 (edited) ( reserved ..) Edited June 23, 2018 by Deye Link to comment Share on other sites More sharing options...
Deye Posted June 23, 2018 Author Share Posted June 23, 2018 Changed to improve the interface, its now toolful 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