Leaderboard
Popular Content
Showing content with the highest reputation on 10/12/2016 in all areas
-
I wrote this Roman numeral conversion function a while ago, but never got round to writing the reverse function. This is a very simple example aimed more at beginners: sometimes you need a break from trying to figure out the more complicated stuff. I decided to post this mini UDF just in case someone might make use of it. The regexp in the _IsRoman() validation function might also be of interest to some of the more advanced members. Maybe it can be improved. #include-once ; #INDEX# ====================================================================================================================== ; Title .........: Roman ; AutoIt Version : 3.3.14.2 ; Language ......: English ; Description ...: Roman numeral conversion and validation. ; Notes .........: Roman numerals range between 1 and 3999. ; Author(s) .....: czardas ; ============================================================================================================================== ; #CURRENT# ==================================================================================================================== ; _IsRoman ; _Roman ; _RomanToDec ; ============================================================================================================================== ; #FUNCTION# =================================================================================================================== ; Name...........: _IsRoman ; Description ...: Tests if a string is a roman numeral. ; Syntax.........: _IsRoman($sRoman) ; Parameters.....; $sRoman - The string to test. ; Return values .: Returns True or False and sets @error to 1 if the parameter is an empty string. ; Author ........: czardas ; ============================================================================================================================== Func _IsRoman($sRoman) If $sRoman = '' Then Return SetError(1, 0, False) $sRoman = StringRegExpReplace($sRoman, '(?i)(\A)(M{0,3})?(CM|DC{0,3}|CD|C{0,3})?(XC|LX{0,3}|XL|X{0,3})?(IX|VI{0,3}|IV|I{0,3})?', '') Return $sRoman = '' EndFunc ;==>_IsRoman ; #FUNCTION# =================================================================================================================== ; Name...........: _Roman ; Description ...: Converts a decimal integer to a roman numeral. ; Syntax.........: _Roman($iInt) ; Parameters.....; $iInt - The integer to convert. ; Return values .: Returns the integer converted to a Roman numeral. ; Sets @error to 1 and returns an empty string if the integer is out of bounds. ; Author ........: czardas ; ============================================================================================================================== Func _Roman($iInt) If Not StringIsInt($iInt) Or $iInt > 3999 Or $iInt < 1 Then Return SetError(1, 0, "") $iInt = Int($iInt) ; in case the string contains leading zeros Local $aNumeral[10][4] = _ [["","","",""], _ ["M","C","X","I"], _ ["MM","CC","XX","II"], _ ["MMM","CCC","XXX","III"], _ ["","CD","XL","IV"], _ ["","D","L","V"], _ ["","DC","LX","VI"], _ ["","DCC","LXX","VII"], _ ["","DCCC","LXXX","VIII"], _ ["","CM","XC","IX"]] Local $iOffset = StringLen($iInt) -4, $sRoman = "", $aDecimal = StringSplit($iInt, "", 2) For $i = 0 To UBound($aDecimal) -1 $sRoman &= $aNumeral[$aDecimal[$i]][$i -$iOffset] Next Return $sRoman EndFunc ;==>_Roman ; #FUNCTION# =================================================================================================================== ; Name...........: _RomanToDec ; Description ...: Converts a roman numeral to a decimal integer. ; Syntax.........: _RomanToDec($sRoman) ; Parameters.....; $sRoman - The Roman numeral to convert. ; Return values .: Returns the Roman numeral converted to an integer. ; Sets @error to 1 and returns an empty string if the Roman numeral is invalid. ; Author ........: czardas ; ============================================================================================================================== Func _RomanToDec($sRoman) If Not _IsRoman($sRoman) Then Return SetError(1, 0, '') Local $aChar = StringSplit($sRoman, '') For $i = 1 To $aChar[0] Switch $aChar[$i] Case 'I' $aChar[$i] = 1 Case 'V' $aChar[$i] = 5 Case 'X' $aChar[$i] = 10 Case 'L' $aChar[$i] = 50 Case 'C' $aChar[$i] = 100 Case 'D' $aChar[$i] = 500 Case 'M' $aChar[$i] = 1000 EndSwitch Next Local $iCount = 0, $iCurr, $iNext For $i = 1 To $aChar[0] $iCurr = $aChar[$i] If $i < $aChar[0] Then $iNext = $aChar[$i +1] If $iNext > $iCurr Then $iCurr = $iNext - $iCurr $i += 1 ; skip the next element EndIf EndIf $iCount += $iCurr Next Return $iCount EndFunc ;==>_RomanToDec Simple Demo #include <Array.au3> #include 'Roman.au3' Local $aRoman[4000] = [3999] For $i = 1 To 3999 $aRoman[$i] = _Roman($i) Next _ArrayShuffle($aRoman, 1) ; shuffle the array starting from Row 1 _ArrayDisplay($aRoman, "Shuffled") RomanSort($aRoman, 1) ; sort the roman numerals by size _ArrayDisplay($aRoman, "Sorted") Func RomanSort(ByRef $aArray, $iStart = Default, $iStop = Default) If Not IsArray($aArray) Or UBound($aArray, 0) <> 1 Then Return SetError(1) ; simple 1D array demo $iStart = ($iStart = Default ? 0 : Int($iStart)) $iStop = ($iStop = Default ? UBound($aArray) -1 : Int($iStop)) If $iStart < 0 Or $iStart > $iStop Or $iStop > UBound($aArray) -1 Then Return SetError(2) ; out of bounds For $i = $iStart To $iStop If Not _IsRoman($aArray[$i]) Then Return SetError(3) ; Roman numerals only [other solutions are beyond the scope of this simple demo] $aArray[$i] = _RomanToDec($aArray[$i]) ; convert to decimal Next _ArraySort($aArray, 0, $iStart, $iStop) ; sort integers For $i = $iStart To $iStop $aArray[$i] = _Roman($aArray[$i]) ; convert back to Roman numerals Next EndFunc ;==> RomanSort2 points
-
[Solved] Smartphone IE browser emulation
Exit reacted to Blue_Drache for a topic
HttpSetUserAgent("MyUserAgent") Wouldn't using this be simpler?1 point -
You can do this. #include <IE.au3> Local $oIE = _IECreate() Sleep(1000) $oIE.Navigate2("http://www.useragentstring.com/", Default, Default, Default, _ "User-Agent: Mozilla/5.0 (Mobile; Windows Phone 8.1; Android 4.0; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 520) like iPhone OS 7_0_3 Mac OS X AppleWebKit/537 (KHTML, like Gecko) Mobile Safari/537") Saludos1 point
-
One-line regex : Local $str = 'XX-EXCHG01,XX-GLG65J4,XY-GLG65J4,XX-4JG5L6G,COMPUT3R' Local $aOriginal = StringSplit($str, ',', 3) For $i = 0 To UBound($aOriginal) - 1 ConsoleWrite($aOriginal[$i] & (_TestString($aOriginal[$i]) ? ' matches' : ' does not match' ) & @CRLF) Next Func _TestString($sTest) Return StringRegExp($sTest, "^XX-(?=(?:\d*[A-Z]){4})(?=(?:[A-Z]*\d){3})[A-Z0-9]{7}$") EndFunc1 point
-
My current favorite is FreeBasic, easy to learn and very fast! My latest code in FB -> moving 69.696 pixels in 30fps on my notebook. Just move your mouse over the image to see the effect. PS: I know that you are not looking for such kind of things...1 point
-
I would remove only number replicates from an array this way. #include <Array.au3> ; ------- Create Array ---------- $a = StringRegExp(StringRegExpReplace(FileRead(@ScriptName), "(?s)^.*#cs\v+|\v+#ce.*$", ""), "\s*(.+)\s*", 3) _ArrayDisplay($a, "Original") ; ------- End of Create Array ---------- ; Remove only number duplicates from array. Local $sUniqueStr = "|" For $i = UBound($a) - 1 To 0 Step -1 If Not StringRegExp($a[$i], "[^\d.]") Then ; Check if the array element contains only digits, and maybe, a decimal point. If StringInStr($sUniqueStr, "|" & $a[$i] & "|") Then _ArrayDelete($a, $i) ; The number already exists in the $sUniqueStr string. Else $sUniqueStr &= $a[$i] & "|" ; Add only unique numbers to $sUniqueStr string. EndIf EndIf Next _ArrayDisplay($a, "Unique Numbers") #cs sku1 12.00 2.00 Taglia 32 32 Taglia coppa A Taglia torace S Fantasia A righe sku2 12.00 1.00 Taglia 34 34 Taglia coppa A AA Taglia torace S Colore principale Arancione Colore esatto Albicocca sku3 12.00 1.00 Taglia 36 36 AA S Materiale Lycra #ce1 point
-
One of possible solutions: #include <MsgBoxConstants.au3> #include <StringConstants.au3> $sData='ID:9999 | James Crawler | Data Entry | Age: 19 | MTWTF|RM101' $aSplit=StringSplit($sData,'|', $STR_NOCOUNT) MsgBox($MB_ICONINFORMATION,'Wanted:',$aSplit[1])1 point
-
This seems to be a relatively simple sorting. You just sort the rows by one column at a time in ascending order. Only the subitems in this specific column are used for the sorting. The column with the checkboxes does not contain any text values. This column is sorted by the checked state. You can implement such a sorting in a normal listview if you create your own sorting function. You don't need a virtual listview for that. Or will the listview contain a large number of rows? And then you want to use a virtual listview of performance reasons. How many rows and columns do you expect the listview will contain? What is the data source for the listview? Where do you get the data from? I've added the checkboxes to an otherwise empty column and created a sorting function for it. I've set some of the checkboxes to the checked state in advance. Virtual ListViews.7z The Ternary operator is almost twice as fast as an If...Else...EndIf block. It's very useful in loops and in fast repeated calls of for example VM_Message handler functions.1 point
-
Open any excel file as an array
232showtime reacted to water for a topic
Why not use _Excel_RangeRead?1 point -
Hi Martin, Hi All, I am using the Commg.dll since years and it always worked fine. Thank you for the good work, Martin ! Unfortunately on Windows 10 I experience big problems. The Scripts are working but the serial communication seems to be very slow. The problems have been reported in this thread by several people before. Did anybody find a solution for the problem ? Not using Windows 10 is not a solution because sooner or later every PC will run Win10 or Higher ... So it is a matter of time until everybody using the Commg.dll will face the same problem. Best Regards, Gregor1 point