Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 06/18/2015 in all areas

  1. This topic will contain simple and working client server communication example along with some basic info for understanding. Examples are based on multi client communication that is happening on one computer (localhost). Changing (if it's not already set correctly) the IP address parameter on server script to reflect your network device IP address will allow you to communicate with other clients on network or even to communicate on internet if your network settings (forwarded router port, ip address on that port is seen from others on internet, you're not trying to do client server from identical computer on identical internet connection) are configured correctly. Every client connecting will need to have server IP address for network (or server public IP address for internet) connection in his client script. So edit client script to correspond to server address TCPConnect('type server ip address in client', 1018). Sometimes firewall can be your problem, if something isn't working turn off firewall and see if it helps. Server will always listen on his Network Adapter IP Address and not on his public address. In some rare occasions server can be set to listen on 0.0.0.0, with that he will listen from any device that he have physically connected on his MB USB or something third (with localhost included for listening). But i would not know the end result of what will happen if some other program that you have installed need that port (or you started 2 servers that interpret one with another). First part will hold just plain code.Second part will hold identical code with comments below commands for more info and understanding hopefully to help new autoit users to understand what and why that something is there.Other parts will hold additional info.First part: Working Code (working in two way communication, with multiple and-or identical client)Server #include <Array.au3> TCPStartup() Dim $Socket_Data[1] $Socket_Data[0] = 0 $Listen = TCPListen(@IPAddress1, 1018, 500) If @error Then ConsoleWrite('!--> TCPListen error number ( ' & @error & ' ), look in the help file (on MSDN link) on func TCPListen to get more info about this error.' & @CRLF) Exit EndIf While 1 For $x = $Socket_Data[0] To 1 Step -1 $Recv = TCPRecv($Socket_Data[$x], 1000000) If $Recv Then MsgBox(0, 'Client Number ' & $x & ' with connected socket identifier ' & $Socket_Data[$x], 'Recived msg from Client: ' & @CRLF & $Recv, 5) TCPSend($Socket_Data[$x], 'bye') TCPCloseSocket($Socket_Data[$x]) _ArrayDelete($Socket_Data, $x) $Socket_Data[0] -= 1 EndIf Next _Accept() WEnd Func _Accept() Local $Accept = TCPAccept($Listen) If $Accept <> -1 Then _ArrayAdd($Socket_Data, $Accept) $Socket_Data[0] += 1 EndIf EndFunc ;==>_AcceptClient TCPStartup() $Socket = TCPConnect(@IPAddress1, 1018) If @error Then ConsoleWrite('!--> TCPConnect error number ( ' & @error & ' ), look in the help file (on MSDN link) on func TCPConnect to get more info about this error.' & @CRLF) Exit EndIf TCPSend($Socket, 'Hi there. My computer name is' & ", " & @ComputerName & ", and its drive serial is " & DriveGetSerial(@HomeDrive)) Do $Recv = TCPRecv($Socket, 1000000) Until $Recv MsgBox(0, 'Recived from server:', $Recv)Second part: Explained Working Code (for upper communication) Third Part: Understanding for how is msg received with TCPRecv on server (or on client) Forth Part: Packets Fifth Part: How to get or check IP address of your device? Sixth Part: How to forward ports? (2 nice youtube tutorials) Seventh Part: Internet communication? If i wrote something incorrectly or wrong please tell me so that i can correct it. Edited: Local and Global, added aditional info about reciving msgs for maxlen buffer.
    2 points
  2. This is for extraction of data from HTML tables to an array. It uses an raw html source file as input, and does not relies on any browser. You can get the source of the html using commands like InetGet(), InetRead(), _INetGetSource(), _IEDocReadHTML() for example, or load an html file from disc as well. It also takes care of the data position in the table due to rowspan and colspan trying to keep the same layout in the generated array. It has the option to fill the cells in the array corresponding with the "span" zones all with the same value of the first "span" cell of the corresponding area. ; save this as _HtmlTable2Array.au3 #include-once #include <array.au3> ; ; #FUNCTION# ==================================================================================================================== ; Name ..........: _HtmlTableGetList ; Description ...: Finds and enumerates all the html tables contained in an html listing (even if nested). ; if the optional parameter $i_index is passed, then only that table is returned ; Syntax ........: _HtmlTableGetList($sHtml[, $i_index = -1]) ; Parameters ....: $sHtml - A string value containing an html page listing ; $i_index - [optional] An integer value indicating the number of the table to be returned (1 based) ; with the default value of -1 an array with all found tables is returned ; Return values .: Success; Returns an 1D 1 based array containing all or single html table found in the html. ; element [0] (and @extended as well) contains the number of tables found (or 0 if no tables are returned) ; if an error occurs then an ampty string is returned and the following @error code is setted ; @error: 1 - no tables are present in the passed HTML ; 2 - error while parsing tables, (opening and closing tags are not balanced) ; 3 - error while parsing tables, (open/close mismatch error) ; 4 - invalid table index request (requested table nr. is out of boundaries) ; =============================================================================================================================== Func _HtmlTableGetList($sHtml, $i_index = -1) Local $aTables = _ParseTags($sHtml, "<table", "</table>") If @error Then Return SetError(@error, 0, "") ElseIf $i_index = -1 Then Return SetError(0, $aTables[0], $aTables) Else If $i_index > 0 And $i_index <= $aTables[0] Then Local $aTemp[2] = [1, $aTables[$i_index]] Return SetError(0, 1, $aTemp) Else Return SetError(4, 0, "") ; bad index EndIf EndIf EndFunc ;==>_HtmlTableGetList ; #FUNCTION# ==================================================================================================================== ; Name ..........: _HtmlTableWriteToArray ; Description ...: It writes values from an html table to a 2D array. It tries to take care of the rowspan and colspan formats ; Syntax ........: _HtmlTableWriteToArray($sHtmlTable[, $bFillSpan = False[, $iFilter = 0]]) ; Parameters ....: $sHtmlTable - A string value containing the html code of the table to be parsed ; $bFillSpan - [optional] Default is False. If span areas have to be filled by repeating the data ; contained in the first cell of the span area ; $iFilter - [optional] Default is 0 (no filters) data extracted from cells is returned unchanged. ; - 0 = no filter ; - 1 = removes non ascii characters ; - 2 = removes all double whitespaces ; - 4 = removes all double linefeeds ; - 8 = removes all html-tags ; - 16 = simple html-tag / entities convertor ; Return values .: Success: 2D array containing data from the html table ; Faillure: An empty strimg and sets @error as following: ; @error: 1 - no table content is present in the passed HTML ; 2 - error while parsing rows and/or columns, (opening and closing tags are not balanced) ; 3 - error while parsing rows and/or columns, (open/close mismatch error) ; =============================================================================================================================== Func _HtmlTableWriteToArray($sHtmlTable, $bFillSpan = False, $iFilter = 0) $sHtmlTable = StringReplace(StringReplace($sHtmlTable, "<th", "<td"), "</th>", "</td>") ; th becomes td ; rows of the wanted table Local $iError, $aTempEmptyRow[2] = [1, ""] Local $aRows = _ParseTags($sHtmlTable, "<tr", "</tr>") ; $aRows[0] = nr. of rows If @error Then Return SetError(@error, 0, "") Local $aCols[$aRows[0] + 1], $aTemp For $i = 1 To $aRows[0] $aTemp = _ParseTags($aRows[$i], "<td", "</td>") $iError = @error If $iError = 1 Then ; check if it's an empty row $aTemp = $aTempEmptyRow ; Empty Row Else If $iError Then Return SetError($iError, 0, "") EndIf If $aCols[0] < $aTemp[0] Then $aCols[0] = $aTemp[0] ; $aTemp[0] = max nr. of columns in table $aCols[$i] = $aTemp Next Local $aResult[$aRows[0]][$aCols[0]], $iStart, $iEnd, $aRowspan, $aColspan, $iSpanY, $iSpanX, $iSpanRow, $iSpanCol, $iMarkerCode, $sCellContent Local $aMirror = $aResult For $i = 1 To $aRows[0] ; scan all rows in this table $aTemp = $aCols[$i] ; <td ..> xx </td> ..... For $ii = 1 To $aTemp[0] ; scan all cells in this row $iSpanY = 0 $iSpanX = 0 $iY = $i - 1 ; zero base index for vertical ref $iX = $ii - 1 ; zero based indexes for horizontal ref ; following RegExp kindly provided by SadBunny in this post: ; http://www.autoitscript.com/forum/topic/167174-how-to-get-a-number-located-after-a-name-from-within-a-string/?p=1222781 $aRowspan = StringRegExp($aTemp[$ii], "(?i)rowspan\s*=\s*[""']?\s*(\d+)", 1) ; check presence of rowspan If IsArray($aRowspan) Then $iSpanY = $aRowspan[0] - 1 If $iSpanY + $iY > $aRows[0] Then $iSpanY -= $iSpanY + $iY - $aRows[0] + 1 EndIf EndIf ; $aColspan = StringRegExp($aTemp[$ii], "(?i)colspan\s*=\s*[""']?\s*(\d+)", 1) ; check presence of colspan If IsArray($aColspan) Then $iSpanX = $aColspan[0] - 1 ; $iMarkerCode += 1 ; code to mark this span area or single cell If $iSpanY Or $iSpanX Then $iX1 = $iX For $iSpY = 0 To $iSpanY For $iSpX = 0 To $iSpanX $iSpanRow = $iY + $iSpY If $iSpanRow > UBound($aMirror, 1) - 1 Then $iSpanRow = UBound($aMirror, 1) - 1 EndIf $iSpanCol = $iX1 + $iSpX If $iSpanCol > UBound($aMirror, 2) - 1 Then ReDim $aResult[$aRows[0]][UBound($aResult, 2) + 1] ReDim $aMirror[$aRows[0]][UBound($aMirror, 2) + 1] EndIf ; While $aMirror[$iSpanRow][$iX1 + $iSpX] ; search first free column $iX1 += 1 ; $iSpanCol += 1 If $iX1 + $iSpX > UBound($aMirror, 2) - 1 Then ReDim $aResult[$aRows[0]][UBound($aResult, 2) + 1] ReDim $aMirror[$aRows[0]][UBound($aMirror, 2) + 1] EndIf WEnd Next Next EndIf ; $iX1 = $iX ; following RegExp kindly provided by mikell in this post: ; http://www.autoitscript.com/forum/topic/167309-how-to-remove-from-a-string-all-between-and-pairs/?p=1224207 $sCellContent = StringRegExpReplace($aTemp[$ii], '<[^>]+>', "") If $iFilter Then $sCellContent = _HTML_Filter($sCellContent, $iFilter) For $iSpX = 0 To $iSpanX For $iSpY = 0 To $iSpanY $iSpanRow = $iY + $iSpY If $iSpanRow > UBound($aMirror, 1) - 1 Then $iSpanRow = UBound($aMirror, 1) - 1 EndIf While $aMirror[$iSpanRow][$iX1 + $iSpX] $iX1 += 1 If $iX1 + $iSpX > UBound($aMirror, 2) - 1 Then ReDim $aResult[$aRows[0]][$iX1 + $iSpX + 1] ReDim $aMirror[$aRows[0]][$iX1 + $iSpX + 1] EndIf WEnd $aMirror[$iSpanRow][$iX1 + $iSpX] = $iMarkerCode ; 1 If $bFillSpan Then $aResult[$iSpanRow][$iX1 + $iSpX] = $sCellContent Next $aResult[$iY][$iX1] = $sCellContent Next Next Next ; _ArrayDisplay($aMirror, "Debug") Return SetError(0, $aResult[0][0], $aResult) EndFunc ;==>_HtmlTableWriteToArray ; ; #FUNCTION# ==================================================================================================================== ; Name ..........: _HtmlTableGetWriteToArray ; Description ...: extract the html code of the required table from the html listing and copy the data of the table to a 2D array ; Syntax ........: _HtmlTableGetWriteToArray($sHtml[, $iWantedTable = 1[, $bFillSpan = False[, $iFilter = 0]]]) ; Parameters ....: $sHtml - A string value containing the html listing ; $iWantedTable - [optional] An integer value. The nr. of the table to be parsed (default is first table) ; $bFillSpan - [optional] Default is False. If all span areas have to be filled by repeating the data ; contained in the first cell of the span area ; $iFilter - [optional] Default is 0 (no filters) data extracted from cells is returned unchanged. ; - 0 = no filter ; - 1 = removes non ascii characters ; - 2 = removes all double whitespaces ; - 4 = removes all double linefeeds ; - 8 = removes all html-tags ; - 16 = simple html-tag / entities convertor ; Return values .: success: 2D array containing data from the wanted html table. ; faillure: An empty string and sets @error as following: ; @error: 1 - no tables are present in the passed HTML ; 2 - error while parsing tables, (opening and closing tags are not balanced) ; 3 - error while parsing tables, (open/close mismatch error) ; 4 - invalid table index request (requested table nr. is out of boundaries) ; =============================================================================================================================== Func _HtmlTableGetWriteToArray($sHtml, $iWantedTable = 1, $bFillSpan = False, $iFilter = 0) Local $aSingleTable = _HtmlTableGetList($sHtml, $iWantedTable) If @error Then Return SetError(@error, 0, "") Local $aTableData = _HtmlTableWriteToArray($aSingleTable[1], $bFillSpan, $iFilter) If @error Then Return SetError(@error, 0, "") Return SetError(0, $aTableData[0][0], $aTableData) EndFunc ;==>_HtmlTableGetWriteToArray ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ParseTags ; Description ...: searches and extract all portions of html code within opening and closing tags inclusive. ; Returns an array containing a collection of <tag ...... </tag> lines. one in each element (even if are nested) ; Syntax ........: _ParseTags($sHtml, $sOpening, $sClosing) ; Parameters ....: $sHtml - A string value containing the html listing ; $sOpening - A string value indicating the opening tag ; $sClosing - A string value indicating the closing tag ; Return values .: success: an 1D 1 based array containing all the portions of html code representing the element ; element [0] af the array (and @extended as well) contains the counter of found elements ; faillure: An empty string and sets @error as following: ; @error: 1 - no tables are present in the passed HTML ; 2 - error while parsing tables, (opening and closing tags are not balanced) ; 3 - error while parsing tables, (open/close mismatch error) ; 4 - invalid table index request (requested table nr. is out of boundaries) ; =============================================================================================================================== Func _ParseTags($sHtml, $sOpening, $sClosing) ; example: $sOpening = '<table', $sClosing = '</table>' ; it finds how many of such tags are on the HTML page StringReplace($sHtml, $sOpening, $sOpening) ; in @xtended nr. of occurences Local $iNrOfThisTag = @extended ; I assume that opening <tag and closing </tag> tags are balanced (as should be) ; (so NO check is made to see if they are actually balanced) If $iNrOfThisTag Then ; if there is at least one of this tag ; $aThisTagsPositions array will contain the positions of the ; starting <tag and ending </tag> tags within the HTML Local $aThisTagsPositions[$iNrOfThisTag * 2 + 1][3] ; 1 based (make room for all open and close tags) ; 2) find in the HTML the positions of the $sOpening <tag and $sClosing </tag> tags For $i = 1 To $iNrOfThisTag $aThisTagsPositions[$i][0] = StringInStr($sHtml, $sOpening, 0, $i) ; start position of $i occurrence of <tag opening tag $aThisTagsPositions[$i][1] = $sOpening ; it marks which kind of tag is this $aThisTagsPositions[$i][2] = $i ; nr of this tag $aThisTagsPositions[$iNrOfThisTag + $i][0] = StringInStr($sHtml, $sClosing, 0, $i) + StringLen($sClosing) - 1 ; end position of $i^ occurrence of </tag> closing tag $aThisTagsPositions[$iNrOfThisTag + $i][1] = $sClosing ; it marks which kind of tag is this Next _ArraySort($aThisTagsPositions, 0, 1) ; now all opening and closing tags are in the same sequence as them appears in the HTML Local $aStack[UBound($aThisTagsPositions)][2] Local $aTags[Ceiling(UBound($aThisTagsPositions) / 2)] ; will contains the collection of <tag ..... </tag> from the html For $i = 1 To UBound($aThisTagsPositions) - 1 If $aThisTagsPositions[$i][1] = $sOpening Then ; opening <tag $aStack[0][0] += 1 ; nr of tags in html $aStack[$aStack[0][0]][0] = $sOpening $aStack[$aStack[0][0]][1] = $i ElseIf $aThisTagsPositions[$i][1] = $sClosing Then ; a closing </tag> was found If Not $aStack[0][0] Or Not ($aStack[$aStack[0][0]][0] = $sOpening And $aThisTagsPositions[$i][1] = $sClosing) Then Return SetError(3, 0, "") ; Open/Close mismatch error Else ; pair detected (the reciprocal tag) ; now get coordinates of the 2 tags ; 1) extract this tag <tag ..... </tag> from the html to the array $aTags[$aThisTagsPositions[$aStack[$aStack[0][0]][1]][2]] = StringMid($sHtml, $aThisTagsPositions[$aStack[$aStack[0][0]][1]][0], 1 + $aThisTagsPositions[$i][0] - $aThisTagsPositions[$aStack[$aStack[0][0]][1]][0]) ; 2) remove that tag <tag ..... </tag> from the html $sHtml = StringLeft($sHtml, $aThisTagsPositions[$aStack[$aStack[0][0]][1]][0] - 1) & StringMid($sHtml, $aThisTagsPositions[$i][0] + 1) ; 3) adjust the references to the new positions of remaining tags For $ii = $i To UBound($aThisTagsPositions) - 1 $aThisTagsPositions[$ii][0] -= StringLen($aTags[$aThisTagsPositions[$aStack[$aStack[0][0]][1]][2]]) Next $aStack[0][0] -= 1 ; nr of tags still in html EndIf EndIf Next If Not $aStack[0][0] Then ; all tags where parsed correctly $aTags[0] = $iNrOfThisTag Return SetError(0, $iNrOfThisTag, $aTags) ; OK Else Return SetError(2, 0, "") ; opening and closing tags are not balanced EndIf Else Return SetError(1, 0, "") ; there are no of such tags on this HTML page EndIf EndFunc ;==>_ParseTags ; #============================================================================= ; Name ..........: _HTML_Filter ; Description ...: Filter for strings ; AutoIt Version : V3.3.0.0 ; Syntax ........: _HTML_Filter(ByRef $sString[, $iMode = 0]) ; Parameter(s): .: $sString - String to filter ; $iMode - Optional: (Default = 0) : removes nothing ; - 0 = no filter ; - 1 = removes non ascii characters ; - 2 = removes all double whitespaces ; - 4 = removes all double linefeeds ; - 8 = removes all html-tags ; - 16 = simple html-tag / entities convertor ; Return Value ..: Success - Filterd String ; Failure - Input String ; Author(s) .....: Thorsten Willert, Stephen Podhajecki {gehossafats at netmdc. com} _ConvertEntities ; Date ..........: Wed Jan 27 20:49:59 CET 2010 ; modified ......: by Chimp Removed a double "&nbsp;" entities declaration, ; replace it with char(160) instead of chr(32), ; declaration of the $aEntities array as Static instead of just Local ; ============================================================================== Func _HTML_Filter(ByRef $sString, $iMode = 0) If $iMode = 0 Then Return $sString ;16 simple HTML tag / entities converter If $iMode >= 16 And $iMode < 32 Then Static Local $aEntities[95][2] = [["&quot;", 34],["&amp;", 38],["&lt;", 60],["&gt;", 62],["&nbsp;", 160] _ ,["&iexcl;", 161],["&cent;", 162],["&pound;", 163],["&curren;", 164],["&yen;", 165],["&brvbar;", 166] _ ,["&sect;", 167],["&uml;", 168],["&copy;", 169],["&ordf;", 170],["&not;", 172],["&shy;", 173] _ ,["&reg;", 174],["&macr;", 175],["&deg;", 176],["&plusmn;", 177],["&sup2;", 178],["&sup3;", 179] _ ,["&acute;", 180],["&micro;", 181],["&para;", 182],["&middot;", 183],["&cedil;", 184],["&sup1;", 185] _ ,["&ordm;", 186],["&raquo;", 187],["&frac14;", 188],["&frac12;", 189],["&frac34;", 190],["&iquest;", 191] _ ,["&Agrave;", 192],["&Aacute;", 193],["&Atilde;", 195],["&Auml;", 196],["&Aring;", 197],["&AElig;", 198] _ ,["&Ccedil;", 199],["&Egrave;", 200],["&Eacute;", 201],["&Ecirc;", 202],["&Igrave;", 204],["&Iacute;", 205] _ ,["&Icirc;", 206],["&Iuml;", 207],["&ETH;", 208],["&Ntilde;", 209],["&Ograve;", 210],["&Oacute;", 211] _ ,["&Ocirc;", 212],["&Otilde;", 213],["&Ouml;", 214],["&times;", 215],["&Oslash;", 216],["&Ugrave;", 217] _ ,["&Uacute;", 218],["&Ucirc;", 219],["&Uuml;", 220],["&Yacute;", 221],["&THORN;", 222],["&szlig;", 223] _ ,["&agrave;", 224],["&aacute;", 225],["&acirc;", 226],["&atilde;", 227],["&auml;", 228],["&aring;", 229] _ ,["&aelig;", 230],["&ccedil;", 231],["&egrave;", 232],["&eacute;", 233],["&ecirc;", 234],["&euml;", 235] _ ,["&igrave;", 236],["&iacute;", 237],["&icirc;", 238],["&iuml;", 239],["&eth;", 240],["&ntilde;", 241] _ ,["&ograve;", 242],["&oacute;", 243],["&ocirc;", 244],["&otilde;", 245],["&ouml;", 246],["&divide;", 247] _ ,["&oslash;", 248],["&ugrave;", 249],["&uacute;", 250],["&ucirc;", 251],["&uuml;", 252],["&thorn;", 254]] $sString = StringRegExpReplace($sString, '(?i)<p.*?>', @CRLF & @CRLF) $sString = StringRegExpReplace($sString, '(?i)<br>', @CRLF) Local $iE = UBound($aEntities) - 1 For $x = 0 To $iE $sString = StringReplace($sString, $aEntities[$x][0], Chr($aEntities[$x][1]), 0, 2) Next For $x = 32 To 255 $sString = StringReplace($sString, "&#" & $x & ";", Chr($x)) Next $iMode -= 16 EndIf ;8 Tag filter If $iMode >= 8 And $iMode < 16 Then ;$sString = StringRegExpReplace($sString, '<script.*?>.*?</script>', "") $sString = StringRegExpReplace($sString, "<[^>]*>", "") $iMode -= 8 EndIf ; 4 remove all double cr, lf If $iMode >= 4 And $iMode < 8 Then $sString = StringRegExpReplace($sString, "([ \t]*[\n\r]+[ \t]*)", @CRLF) $sString = StringRegExpReplace($sString, "[\n\r]+", @CRLF) $iMode -= 4 EndIf ; 2 remove all double withespaces If $iMode = 2 Or $iMode = 3 Then $sString = StringRegExpReplace($sString, "[[:blank:]]+", " ") $sString = StringRegExpReplace($sString, "\n[[:blank:]]+", @CRLF) $sString = StringRegExpReplace($sString, "[[:blank:]]+\n", "") $iMode -= 2 EndIf ; 1 remove all non ASCII (remove all chars with ascii code > 127) If $iMode = 1 Then $sString = StringRegExpReplace($sString, "[^\x00-\x7F]", " ") EndIf Return $sString EndFunc ;==>_HTML_Filter This simple demo allow to test those functions, showing what it can extract from the html tables in a web page of your choice or loading the html file from the disc. ; #include <_HtmlTable2Array.au3> ; <--- udf already included (hard coded) at bottom of this demo #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> #include <File.au3> ; needed for _FileWriteFromArray() #include <array.au3> #include <IE.au3> Local $oIE1 = _IECreateEmbedded(), $oIE2 = _IECreateEmbedded(), $iFilter = 0 Local $sHtml_File, $iIndex, $aTable, $aMyArray, $sFilePath GUICreate("Html tables to array demo", 1000, 450, (@DesktopWidth - 1000) / 2, (@DesktopHeight - 450) / 2 _ , $WS_OVERLAPPEDWINDOW + $WS_CLIPSIBLINGS + $WS_CLIPCHILDREN) GUICtrlCreateObj($oIE1, 010, 10, 480, 360) ; left browser GUICtrlCreateTab(500, 10, 480, 360) GUICtrlCreateTabItem("view table") GUICtrlCreateObj($oIE2, 502, 33, 474, 335) ; right browser GUICtrlCreateTabItem("view html") Local $idLabel_HtmlTable = GUICtrlCreateInput("", 502, 33, 474, 335, $ES_MULTILINE + $ES_AUTOVSCROLL) GUICtrlSetFont(-1, 10, 0, 0, "Courier new") GUICtrlCreateTabItem("") Local $idInputUrl = GUICtrlCreateInput("", 10, 380, 440, 20) Local $idButton_Go = GUICtrlCreateButton("Go", 455, 380, 25, 20) Local $idButton_Load = GUICtrlCreateButton("Load html from disk", 10, 410, 480, 30) Local $idButton_Prev = GUICtrlCreateButton("Prev <-", 510, 375, 50, 30) Local $idLabel_NunTable = GUICtrlCreateLabel("00 / 00", 570, 375, 40, 30) GUICtrlSetFont(-1, 9, 700) Local $idButton_Next = GUICtrlCreateButton("Next ->", 620, 375, 50, 30) GUICtrlCreateGroup("Fill Span", 680, 370, 80, 40) Local $iFillSpan = GUICtrlCreateCheckbox("", 715, 388, 15, 15) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group Local $idButton_Array0 = GUICtrlCreateButton("Preview array", 770, 375, 100, 30) Local $idButton_Array1 = GUICtrlCreateButton("Write array to file", 880, 375, 100, 30) ; options for filtering GUICtrlCreateGroup("Filters", 510, 410, 470, 35) Local $iFilter01 = GUICtrlCreateCheckbox("non ascii", 520, 425, 85, 15) Local $iFilter02 = GUICtrlCreateCheckbox("double spaces", 610, 425, 85, 15) Local $iFilter04 = GUICtrlCreateCheckbox("double @LF", 700, 425, 85, 15) Local $iFilter08 = GUICtrlCreateCheckbox("html-tags", 790, 425, 85, 15) Local $iFilter16 = GUICtrlCreateCheckbox("tags to entities", 880, 425, 85, 15) GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group GUISetState(@SW_SHOW) ;Show GUI ; _IEDocWriteHTML($oIE2, "<HTML></HTML>") GUICtrlSetData($idInputUrl, "http://www.danshort.com/HTMLentities/") ; GUICtrlSetData($idInputUrl, "http://www.mojotoad.com/sisk/projects/HTML-TableExtract/tables.html") ; example page ControlClick("", "", $idButton_Go) ; _IEAction($oIE1, "stop") Do; Waiting for user to close the window $iMsg = GUIGetMsg() Select Case $iMsg = $idButton_Go _IENavigate($oIE1, GUICtrlRead($idInputUrl)) ; _IEAction($oIE1, "stop") $aTables = _HtmlTableGetList(_IEBodyReadHTML($oIE1)) If Not @error Then ; _ArrayDisplay($aTables, "Tables contained in this html") $iIndex = 1 _IEBodyWriteHTML($oIE2, "<html>" & $aTables[$iIndex] & "</html>") ControlClick("", "", $idButton_Prev) _IEAction($oIE2, "stop") Else MsgBox(0, 0, "@error " & @error) EndIf Case $iMsg = $idButton_Load ConsoleWrite("$idButton_Load" & @CRLF) $sHtml_File = FileOpenDialog("Choose an html file", @ScriptDir & "\", "html page (*.htm;*.html)") If Not @error Then GUICtrlSetData($idInputUrl, $sHtml_File) ControlClick("", "", $idButton_Go) EndIf Case $iMsg = $idButton_Next If IsArray($aTables) Then $iIndex += $iIndex < $aTables[0] GUICtrlSetData($idLabel_NunTable, "Table" & @CRLF & $iIndex & " / " & $aTables[0]) GUICtrlSetData($idLabel_HtmlTable, $aTables[$iIndex]) _IEBodyWriteHTML($oIE2, "<html>" & $aTables[$iIndex] & "</html>") _IEAction($oIE2, "stop") EndIf Case $iMsg = $idButton_Prev If IsArray($aTables) Then $iIndex -= $iIndex > 1 GUICtrlSetData($idLabel_NunTable, "Table" & @CRLF & $iIndex & " / " & $aTables[0]) GUICtrlSetData($idLabel_HtmlTable, $aTables[$iIndex]) _IEBodyWriteHTML($oIE2, "<html>" & $aTables[$iIndex] & "</html>") _IEAction($oIE2, "stop") EndIf Case $iMsg = $idButton_Array0 ; Preview Array If IsArray($aTables) Then $iFilter = 1 * _IsChecked($iFilter01) + 2 * _IsChecked($iFilter02) + 4 * _IsChecked($iFilter04) + 8 * _IsChecked($iFilter08) + 16 * _IsChecked($iFilter16) $aMyArray = _HtmlTableWriteToArray($aTables[$iIndex], _IsChecked($iFillSpan), $iFilter) If Not @error Then _ArrayDisplay($aMyArray) EndIf Case $iMsg = $idButton_Array1 ; Saves the array in a csv file of your choice If IsArray($aTables) Then $iFilter = 1 * _IsChecked($iFilter01) + 2 * _IsChecked($iFilter02) + 4 * _IsChecked($iFilter04) + 8 * _IsChecked($iFilter08) + 16 * _IsChecked($iFilter16) $aMyArray = _HtmlTableWriteToArray($aTables[$iIndex], _IsChecked($iFillSpan), $iFilter) If Not @error Then $sFilePath = FileSaveDialog("Choose a file to save to", @ScriptDir, "(*.csv)") If $sFilePath <> "" Then If Not _FileWriteFromArray($sFilePath, $aMyArray, 0, Default, ",") Then MsgBox(0, "Error on file write", "Error code is " & @error & @CRLF & @CRLF & "@error meaning:" & @CRLF & _ "1 - Error opening specified file" & @CRLF & _ "2 - $aArray is not an array" & @CRLF & _ "3 - Error writing to file" & @CRLF & _ "4 - $aArray is not a 1D or 2D array" & @CRLF & _ "5 - Start index is greater than the $iUbound parameter") EndIf EndIf EndIf EndIf EndSelect Until $iMsg = $GUI_EVENT_CLOSE GUIDelete() ; returns 1 if CheckBox is checked Func _IsChecked($idControlID) ; $GUI_CHECKED = 1 Return GUICtrlRead($idControlID) = $GUI_CHECKED EndFunc ;==>_IsChecked ; ------------------------------------------------------------------------ ; Following code should be included by the #include <_HtmlTable2Array.au3> ; hard coded here for easy load an run to try the example ; ------------------------------------------------------------------------ #include-once #include <array.au3> ; ; #FUNCTION# ==================================================================================================================== ; Name ..........: _HtmlTableGetList ; Description ...: Finds and enumerates all the html tables contained in an html listing (even if nested). ; if the optional parameter $i_index is passed, then only that table is returned ; Syntax ........: _HtmlTableGetList($sHtml[, $i_index = -1]) ; Parameters ....: $sHtml - A string value containing an html page listing ; $i_index - [optional] An integer value indicating the number of the table to be returned (1 based) ; with the default value of -1 an array with all found tables is returned ; Return values .: Success; Returns an 1D 1 based array containing all or single html table found in the html. ; element [0] (and @extended as well) contains the number of tables found (or 0 if no tables are returned) ; if an error occurs then an ampty string is returned and the following @error code is setted ; @error: 1 - no tables are present in the passed HTML ; 2 - error while parsing tables, (opening and closing tags are not balanced) ; 3 - error while parsing tables, (open/close mismatch error) ; 4 - invalid table index request (requested table nr. is out of boundaries) ; =============================================================================================================================== Func _HtmlTableGetList($sHtml, $i_index = -1) Local $aTables = _ParseTags($sHtml, "<table", "</table>") If @error Then Return SetError(@error, 0, "") ElseIf $i_index = -1 Then Return SetError(0, $aTables[0], $aTables) Else If $i_index > 0 And $i_index <= $aTables[0] Then Local $aTemp[2] = [1, $aTables[$i_index]] Return SetError(0, 1, $aTemp) Else Return SetError(4, 0, "") ; bad index EndIf EndIf EndFunc ;==>_HtmlTableGetList ; #FUNCTION# ==================================================================================================================== ; Name ..........: _HtmlTableWriteToArray ; Description ...: It writes values from an html table to a 2D array. It tries to take care of the rowspan and colspan formats ; Syntax ........: _HtmlTableWriteToArray($sHtmlTable[, $bFillSpan = False[, $iFilter = 0]]) ; Parameters ....: $sHtmlTable - A string value containing the html code of the table to be parsed ; $bFillSpan - [optional] Default is False. If span areas have to be filled by repeating the data ; contained in the first cell of the span area ; $iFilter - [optional] Default is 0 (no filters) data extracted from cells is returned unchanged. ; - 0 = no filter ; - 1 = removes non ascii characters ; - 2 = removes all double whitespaces ; - 4 = removes all double linefeeds ; - 8 = removes all html-tags ; - 16 = simple html-tag / entities convertor ; Return values .: Success: 2D array containing data from the html table ; Faillure: An empty strimg and sets @error as following: ; @error: 1 - no table content is present in the passed HTML ; 2 - error while parsing rows and/or columns, (opening and closing tags are not balanced) ; 3 - error while parsing rows and/or columns, (open/close mismatch error) ; =============================================================================================================================== Func _HtmlTableWriteToArray($sHtmlTable, $bFillSpan = False, $iFilter = 0) $sHtmlTable = StringReplace(StringReplace($sHtmlTable, "<th", "<td"), "</th>", "</td>") ; th becomes td ; rows of the wanted table Local $iError, $aTempEmptyRow[2] = [1, ""] Local $aRows = _ParseTags($sHtmlTable, "<tr", "</tr>") ; $aRows[0] = nr. of rows If @error Then Return SetError(@error, 0, "") Local $aCols[$aRows[0] + 1], $aTemp For $i = 1 To $aRows[0] $aTemp = _ParseTags($aRows[$i], "<td", "</td>") $iError = @error If $iError = 1 Then ; check if it's an empty row $aTemp = $aTempEmptyRow ; Empty Row Else If $iError Then Return SetError($iError, 0, "") EndIf If $aCols[0] < $aTemp[0] Then $aCols[0] = $aTemp[0] ; $aTemp[0] = max nr. of columns in table $aCols[$i] = $aTemp Next Local $aResult[$aRows[0]][$aCols[0]], $iStart, $iEnd, $aRowspan, $aColspan, $iSpanY, $iSpanX, $iSpanRow, $iSpanCol, $iMarkerCode, $sCellContent Local $aMirror = $aResult For $i = 1 To $aRows[0] ; scan all rows in this table $aTemp = $aCols[$i] ; <td ..> xx </td> ..... For $ii = 1 To $aTemp[0] ; scan all cells in this row $iSpanY = 0 $iSpanX = 0 $iY = $i - 1 ; zero base index for vertical ref $iX = $ii - 1 ; zero based indexes for horizontal ref ; following RegExp kindly provided by SadBunny in this post: ; http://www.autoitscript.com/forum/topic/167174-how-to-get-a-number-located-after-a-name-from-within-a-string/?p=1222781 $aRowspan = StringRegExp($aTemp[$ii], "(?i)rowspan\s*=\s*[""']?\s*(\d+)", 1) ; check presence of rowspan If IsArray($aRowspan) Then $iSpanY = $aRowspan[0] - 1 If $iSpanY + $iY > $aRows[0] Then $iSpanY -= $iSpanY + $iY - $aRows[0] + 1 EndIf EndIf ; $aColspan = StringRegExp($aTemp[$ii], "(?i)colspan\s*=\s*[""']?\s*(\d+)", 1) ; check presence of colspan If IsArray($aColspan) Then $iSpanX = $aColspan[0] - 1 ; $iMarkerCode += 1 ; code to mark this span area or single cell If $iSpanY Or $iSpanX Then $iX1 = $iX For $iSpY = 0 To $iSpanY For $iSpX = 0 To $iSpanX $iSpanRow = $iY + $iSpY If $iSpanRow > UBound($aMirror, 1) - 1 Then $iSpanRow = UBound($aMirror, 1) - 1 EndIf $iSpanCol = $iX1 + $iSpX If $iSpanCol > UBound($aMirror, 2) - 1 Then ReDim $aResult[$aRows[0]][UBound($aResult, 2) + 1] ReDim $aMirror[$aRows[0]][UBound($aMirror, 2) + 1] EndIf ; While $aMirror[$iSpanRow][$iX1 + $iSpX] ; search first free column $iX1 += 1 ; $iSpanCol += 1 If $iX1 + $iSpX > UBound($aMirror, 2) - 1 Then ReDim $aResult[$aRows[0]][UBound($aResult, 2) + 1] ReDim $aMirror[$aRows[0]][UBound($aMirror, 2) + 1] EndIf WEnd Next Next EndIf ; $iX1 = $iX ; following RegExp kindly provided by mikell in this post: ; http://www.autoitscript.com/forum/topic/167309-how-to-remove-from-a-string-all-between-and-pairs/?p=1224207 $sCellContent = StringRegExpReplace($aTemp[$ii], '<[^>]+>', "") If $iFilter Then $sCellContent = _HTML_Filter($sCellContent, $iFilter) For $iSpX = 0 To $iSpanX For $iSpY = 0 To $iSpanY $iSpanRow = $iY + $iSpY If $iSpanRow > UBound($aMirror, 1) - 1 Then $iSpanRow = UBound($aMirror, 1) - 1 EndIf While $aMirror[$iSpanRow][$iX1 + $iSpX] $iX1 += 1 If $iX1 + $iSpX > UBound($aMirror, 2) - 1 Then ReDim $aResult[$aRows[0]][$iX1 + $iSpX + 1] ReDim $aMirror[$aRows[0]][$iX1 + $iSpX + 1] EndIf WEnd $aMirror[$iSpanRow][$iX1 + $iSpX] = $iMarkerCode ; 1 If $bFillSpan Then $aResult[$iSpanRow][$iX1 + $iSpX] = $sCellContent Next $aResult[$iY][$iX1] = $sCellContent Next Next Next ; _ArrayDisplay($aMirror, "Debug") Return SetError(0, $aResult[0][0], $aResult) EndFunc ;==>_HtmlTableWriteToArray ; ; #FUNCTION# ==================================================================================================================== ; Name ..........: _HtmlTableGetWriteToArray ; Description ...: extract the html code of the required table from the html listing and copy the data of the table to a 2D array ; Syntax ........: _HtmlTableGetWriteToArray($sHtml[, $iWantedTable = 1[, $bFillSpan = False[, $iFilter = 0]]]) ; Parameters ....: $sHtml - A string value containing the html listing ; $iWantedTable - [optional] An integer value. The nr. of the table to be parsed (default is first table) ; $bFillSpan - [optional] Default is False. If all span areas have to be filled by repeating the data ; contained in the first cell of the span area ; $iFilter - [optional] Default is 0 (no filters) data extracted from cells is returned unchanged. ; - 0 = no filter ; - 1 = removes non ascii characters ; - 2 = removes all double whitespaces ; - 4 = removes all double linefeeds ; - 8 = removes all html-tags ; - 16 = simple html-tag / entities convertor ; Return values .: success: 2D array containing data from the wanted html table. ; faillure: An empty string and sets @error as following: ; @error: 1 - no tables are present in the passed HTML ; 2 - error while parsing tables, (opening and closing tags are not balanced) ; 3 - error while parsing tables, (open/close mismatch error) ; 4 - invalid table index request (requested table nr. is out of boundaries) ; =============================================================================================================================== Func _HtmlTableGetWriteToArray($sHtml, $iWantedTable = 1, $bFillSpan = False, $iFilter = 0) Local $aSingleTable = _HtmlTableGetList($sHtml, $iWantedTable) If @error Then Return SetError(@error, 0, "") Local $aTableData = _HtmlTableWriteToArray($aSingleTable[1], $bFillSpan, $iFilter) If @error Then Return SetError(@error, 0, "") Return SetError(0, $aTableData[0][0], $aTableData) EndFunc ;==>_HtmlTableGetWriteToArray ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ParseTags ; Description ...: searches and extract all portions of html code within opening and closing tags inclusive. ; Returns an array containing a collection of <tag ...... </tag> lines. one in each element (even if are nested) ; Syntax ........: _ParseTags($sHtml, $sOpening, $sClosing) ; Parameters ....: $sHtml - A string value containing the html listing ; $sOpening - A string value indicating the opening tag ; $sClosing - A string value indicating the closing tag ; Return values .: success: an 1D 1 based array containing all the portions of html code representing the element ; element [0] af the array (and @extended as well) contains the counter of found elements ; faillure: An empty string and sets @error as following: ; @error: 1 - no tables are present in the passed HTML ; 2 - error while parsing tables, (opening and closing tags are not balanced) ; 3 - error while parsing tables, (open/close mismatch error) ; 4 - invalid table index request (requested table nr. is out of boundaries) ; =============================================================================================================================== Func _ParseTags($sHtml, $sOpening, $sClosing) ; example: $sOpening = '<table', $sClosing = '</table>' ; it finds how many of such tags are on the HTML page StringReplace($sHtml, $sOpening, $sOpening) ; in @xtended nr. of occurences Local $iNrOfThisTag = @extended ; I assume that opening <tag and closing </tag> tags are balanced (as should be) ; (so NO check is made to see if they are actually balanced) If $iNrOfThisTag Then ; if there is at least one of this tag ; $aThisTagsPositions array will contain the positions of the ; starting <tag and ending </tag> tags within the HTML Local $aThisTagsPositions[$iNrOfThisTag * 2 + 1][3] ; 1 based (make room for all open and close tags) ; 2) find in the HTML the positions of the $sOpening <tag and $sClosing </tag> tags For $i = 1 To $iNrOfThisTag $aThisTagsPositions[$i][0] = StringInStr($sHtml, $sOpening, 0, $i) ; start position of $i occurrence of <tag opening tag $aThisTagsPositions[$i][1] = $sOpening ; it marks which kind of tag is this $aThisTagsPositions[$i][2] = $i ; nr of this tag $aThisTagsPositions[$iNrOfThisTag + $i][0] = StringInStr($sHtml, $sClosing, 0, $i) + StringLen($sClosing) - 1 ; end position of $i^ occurrence of </tag> closing tag $aThisTagsPositions[$iNrOfThisTag + $i][1] = $sClosing ; it marks which kind of tag is this Next _ArraySort($aThisTagsPositions, 0, 1) ; now all opening and closing tags are in the same sequence as them appears in the HTML Local $aStack[UBound($aThisTagsPositions)][2] Local $aTags[Ceiling(UBound($aThisTagsPositions) / 2)] ; will contains the collection of <tag ..... </tag> from the html For $i = 1 To UBound($aThisTagsPositions) - 1 If $aThisTagsPositions[$i][1] = $sOpening Then ; opening <tag $aStack[0][0] += 1 ; nr of tags in html $aStack[$aStack[0][0]][0] = $sOpening $aStack[$aStack[0][0]][1] = $i ElseIf $aThisTagsPositions[$i][1] = $sClosing Then ; a closing </tag> was found If Not $aStack[0][0] Or Not ($aStack[$aStack[0][0]][0] = $sOpening And $aThisTagsPositions[$i][1] = $sClosing) Then Return SetError(3, 0, "") ; Open/Close mismatch error Else ; pair detected (the reciprocal tag) ; now get coordinates of the 2 tags ; 1) extract this tag <tag ..... </tag> from the html to the array $aTags[$aThisTagsPositions[$aStack[$aStack[0][0]][1]][2]] = StringMid($sHtml, $aThisTagsPositions[$aStack[$aStack[0][0]][1]][0], 1 + $aThisTagsPositions[$i][0] - $aThisTagsPositions[$aStack[$aStack[0][0]][1]][0]) ; 2) remove that tag <tag ..... </tag> from the html $sHtml = StringLeft($sHtml, $aThisTagsPositions[$aStack[$aStack[0][0]][1]][0] - 1) & StringMid($sHtml, $aThisTagsPositions[$i][0] + 1) ; 3) adjust the references to the new positions of remaining tags For $ii = $i To UBound($aThisTagsPositions) - 1 $aThisTagsPositions[$ii][0] -= StringLen($aTags[$aThisTagsPositions[$aStack[$aStack[0][0]][1]][2]]) Next $aStack[0][0] -= 1 ; nr of tags still in html EndIf EndIf Next If Not $aStack[0][0] Then ; all tags where parsed correctly $aTags[0] = $iNrOfThisTag Return SetError(0, $iNrOfThisTag, $aTags) ; OK Else Return SetError(2, 0, "") ; opening and closing tags are not balanced EndIf Else Return SetError(1, 0, "") ; there are no of such tags on this HTML page EndIf EndFunc ;==>_ParseTags ; #============================================================================= ; Name ..........: _HTML_Filter ; Description ...: Filter for strings ; AutoIt Version : V3.3.0.0 ; Syntax ........: _HTML_Filter(ByRef $sString[, $iMode = 0]) ; Parameter(s): .: $sString - String to filter ; $iMode - Optional: (Default = 0) : removes nothing ; - 0 = no filter ; - 1 = removes non ascii characters ; - 2 = removes all double whitespaces ; - 4 = removes all double linefeeds ; - 8 = removes all html-tags ; - 16 = simple html-tag / entities convertor ; Return Value ..: Success - Filterd String ; Failure - Input String ; Author(s) .....: Thorsten Willert, Stephen Podhajecki {gehossafats at netmdc. com} _ConvertEntities ; Date ..........: Wed Jan 27 20:49:59 CET 2010 ; modified ......: by Chimp Removed a double "&nbsp;" entities declaration, ; replace it with char(160) instead of chr(32), ; declaration of the $aEntities array as Static instead of just Local ; ============================================================================== Func _HTML_Filter(ByRef $sString, $iMode = 0) If $iMode = 0 Then Return $sString ;16 simple HTML tag / entities converter If $iMode >= 16 And $iMode < 32 Then Static Local $aEntities[95][2] = [["&quot;", 34],["&amp;", 38],["&lt;", 60],["&gt;", 62],["&nbsp;", 160] _ ,["&iexcl;", 161],["&cent;", 162],["&pound;", 163],["&curren;", 164],["&yen;", 165],["&brvbar;", 166] _ ,["&sect;", 167],["&uml;", 168],["&copy;", 169],["&ordf;", 170],["&not;", 172],["&shy;", 173] _ ,["&reg;", 174],["&macr;", 175],["&deg;", 176],["&plusmn;", 177],["&sup2;", 178],["&sup3;", 179] _ ,["&acute;", 180],["&micro;", 181],["&para;", 182],["&middot;", 183],["&cedil;", 184],["&sup1;", 185] _ ,["&ordm;", 186],["&raquo;", 187],["&frac14;", 188],["&frac12;", 189],["&frac34;", 190],["&iquest;", 191] _ ,["&Agrave;", 192],["&Aacute;", 193],["&Atilde;", 195],["&Auml;", 196],["&Aring;", 197],["&AElig;", 198] _ ,["&Ccedil;", 199],["&Egrave;", 200],["&Eacute;", 201],["&Ecirc;", 202],["&Igrave;", 204],["&Iacute;", 205] _ ,["&Icirc;", 206],["&Iuml;", 207],["&ETH;", 208],["&Ntilde;", 209],["&Ograve;", 210],["&Oacute;", 211] _ ,["&Ocirc;", 212],["&Otilde;", 213],["&Ouml;", 214],["&times;", 215],["&Oslash;", 216],["&Ugrave;", 217] _ ,["&Uacute;", 218],["&Ucirc;", 219],["&Uuml;", 220],["&Yacute;", 221],["&THORN;", 222],["&szlig;", 223] _ ,["&agrave;", 224],["&aacute;", 225],["&acirc;", 226],["&atilde;", 227],["&auml;", 228],["&aring;", 229] _ ,["&aelig;", 230],["&ccedil;", 231],["&egrave;", 232],["&eacute;", 233],["&ecirc;", 234],["&euml;", 235] _ ,["&igrave;", 236],["&iacute;", 237],["&icirc;", 238],["&iuml;", 239],["&eth;", 240],["&ntilde;", 241] _ ,["&ograve;", 242],["&oacute;", 243],["&ocirc;", 244],["&otilde;", 245],["&ouml;", 246],["&divide;", 247] _ ,["&oslash;", 248],["&ugrave;", 249],["&uacute;", 250],["&ucirc;", 251],["&uuml;", 252],["&thorn;", 254]] $sString = StringRegExpReplace($sString, '(?i)<p.*?>', @CRLF & @CRLF) $sString = StringRegExpReplace($sString, '(?i)<br>', @CRLF) Local $iE = UBound($aEntities) - 1 For $x = 0 To $iE $sString = StringReplace($sString, $aEntities[$x][0], Chr($aEntities[$x][1]), 0, 2) Next For $x = 32 To 255 $sString = StringReplace($sString, "&#" & $x & ";", Chr($x)) Next $iMode -= 16 EndIf ;8 Tag filter If $iMode >= 8 And $iMode < 16 Then ;$sString = StringRegExpReplace($sString, '<script.*?>.*?</script>', "") $sString = StringRegExpReplace($sString, "<[^>]*>", "") $iMode -= 8 EndIf ; 4 remove all double cr, lf If $iMode >= 4 And $iMode < 8 Then $sString = StringRegExpReplace($sString, "([ \t]*[\n\r]+[ \t]*)", @CRLF) $sString = StringRegExpReplace($sString, "[\n\r]+", @CRLF) $iMode -= 4 EndIf ; 2 remove all double withespaces If $iMode = 2 Or $iMode = 3 Then $sString = StringRegExpReplace($sString, "[[:blank:]]+", " ") $sString = StringRegExpReplace($sString, "\n[[:blank:]]+", @CRLF) $sString = StringRegExpReplace($sString, "[[:blank:]]+\n", "") $iMode -= 2 EndIf ; 1 remove all non ASCII (remove all chars with ascii code > 127) If $iMode = 1 Then $sString = StringRegExpReplace($sString, "[^\x00-\x7F]", " ") EndIf Return $sString EndFunc ;==>_HTML_Filter Any error reports or suggestions for enhancements are welcome
    1 point
  3. You can also use the _EventLog_* functions, specifically _EventLog_Open and _EventLog_Report.
    1 point
  4. c.haslam, No, you will not get banned - but you make yourself look very stupid. - Do you think you are the first to notice this? You are not. - Is there a Trojan in the Help fie? No. - Have the AV companies been informed? No doubt - I personally inform AVG every time they hit on an AutoIt file. So what more do you want us to do? M23
    1 point
  5. iamtheky

    AutoIt Snippets

    Maybe explain how you feel your example differs from the progressset helpfile. You should be encouraging discourse and then logically defending your position rather than trying to preempt, as the forum is a good place to hone your debate skills in addition to your coding.
    1 point
  6. JLogan3o13

    AutoIt Snippets

    So, you post something that is basically a rehashing of the example under ProgressSet, you're intelligent *cough* enough to foresee people are probably going to point out the snippet's lack of value, but you posted it anyway?
    1 point
  7. water

    AutoIt Snippets

    If you think this are rude commens then you should have a look at other forums and see how rude comments really look like
    1 point
  8. TheDcoder

    AutoIt Snippets

    Second Contribution... Small but neat when you use it ; #FUNCTION# ==================================================================================================================== ; Name ..........: CalcPercent ; Description ...: Calculates Percentage ; Syntax ........: CalcPercent($iPartDone, $iTotal[, $iRoundToDecimalPlace = 1]) ; Parameters ....: $iPartDone - Value of the part which is done. ; $iTotal - The total value. ; $iRoundToDecimalPlace- [optional] Round upto which decimal place?. Default is 1. ; Return values .: Percentage (without % symbol) ; Author ........: TheDcoder ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: http://bit.ly/CalcPercentForAutoIt ; Example .......: Yes, See below ; =============================================================================================================================== Func CalcPercent($iPartDone, $iTotal, $iRoundToDecimalPlace = 1) Return Round(($iPartDone / $iTotal) * 100, $iRoundToDecimalPlace) ; Calculate percentage, round it & return it! EndFunc ;==>CalcPercent ; Example $iCountdown = 60 * 5 ; the value is in seconds ProgressOn("Example for CalcPercent function", "Countdown upto " & $iCountdown & " seconds") $hTimer = TimerInit() For $i = 1 To $iCountdown ProgressSet(CalcPercent($i, $iCountdown)) Sleep(1000) Next $iTime = TimerDiff($hTimer) $iTime /= 1000 ProgressOff() MsgBox(64, "Done!", "The countdown has ended! That took ~" & Round($iTime, 1) & " Seconds.")Hope it may help you, TD P.S Don't reply to this with rude reasons like "Hey! that is so simple! even a newbie can do that." or "It ain't worth posting in snippets section"
    1 point
  9. Hi all, With lots of thanks to weaponx who showed me, StructureConstants.au3 and realised that I had my DllCall mixed up and monoceres for showing me how to create a structure, I present to you AutoIt3 and Aero Glass! Komalo for the original DWMEnableBlurBehind and BrettF for another structure issue. Four functions: _Vista_ApplyGlass($hWnd) - Applies the glass effect to the whole GUI_Vista_ApplyGlassArea($hWnd, $Area) - Applies glass to an area (array) on the GUI_Vista_EnableBlurBehind - Blurs the background of a GUI (still effects controls, need to fix)_Vista_ICE - Returns 1 if DWM is enabled, otherwise 0#include <GUIConstants.au3> $Struct = DllStructCreate("int cxLeftWidth;int cxRightWidth;int cyTopHeight;int cyBottomHeight;") $sStruct = DllStructCreate("dword;int;ptr;int") Global $MyArea[4] = [50, 50, 50, 50] $GUI = GUICreate("Windows Vista DWM", 243, 243) $Apply = GUICtrlCreateButton("Apply", 80, 104, 83, 25, 0) $ICE = GUICtrlCreateButton("DWM Check", 80, 134, 83, 25, 0) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $Apply ;_Vista_ApplyGlass($GUI) ;_Vista_EnableBlurBehind($GUI) _Vista_EnableBlurBehind($GUI) Case $ICE If _Vista_ICE() Then MsgBox(0, "_Vista_ICE", "DWM is enabled!") Else MsgBox(0, "_Vista_ICE", "DWM is NOT enabled!") EndIf EndSwitch WEnd ; #FUNCTION#;=============================================================================== ; ; Name...........: _Vista_ApplyGlass ; Description ...: Applys glass effect to a window ; Syntax.........: _Vista_ApplyGlass($hWnd, [$bColor) ; Parameters ....: $hWnd - Window handle: ; $bColor - Background color ; Return values .: Success - No return ; Failure - Returns 0 ; Author ........: James Brooks ; Modified.......: ; Remarks .......: Thanks to weaponx! ; Related .......: ; Link ..........; ; Example .......; Yes ; ;;========================================================================================== Func _Vista_ApplyGlass($hWnd, $bColor = 0x000000) If @OSVersion <> "WIN_VISTA" Then MsgBox(16, "_Vista_ApplyGlass", "You are not running Vista!") Exit Else GUISetBkColor($bColor); Must be here! $Ret = DllCall("dwmapi.dll", "long", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "long*", DllStructGetPtr($Struct)) If @error Then Return 0 SetError(1) Else Return $Ret EndIf EndIf EndFunc ;==>_Vista_ApplyGlass ; #FUNCTION#;=============================================================================== ; ; Name...........: _Vista_ApplyGlassArea ; Description ...: Applys glass effect to a window area ; Syntax.........: _Vista_ApplyGlassArea($hWnd, $Area, [$bColor) ; Parameters ....: $hWnd - Window handle: ; $Area - Array containing area points ; $bColor - Background color ; Return values .: Success - No return ; Failure - Returns 0 ; Author ........: James Brooks ; Modified.......: ; Remarks .......: Thanks to monoceres! ; Related .......: ; Link ..........; ; Example .......; Yes ; ;;========================================================================================== Func _Vista_ApplyGlassArea($hWnd, $Area, $bColor = 0x000000) If @OSVersion <> "WIN_VISTA" Then MsgBox(16, "_Vista_ApplyGlass", "You are not running Vista!") Exit Else If IsArray($Area) Then DllStructSetData($Struct, "cxLeftWidth", $Area[0]) DllStructSetData($Struct, "cxRightWidth", $Area[1]) DllStructSetData($Struct, "cyTopHeight", $Area[2]) DllStructSetData($Struct, "cyBottomHeight", $Area[3]) GUISetBkColor($bColor); Must be here! $Ret = DllCall("dwmapi.dll", "long*", "DwmExtendFrameIntoClientArea", "hwnd", $hWnd, "ptr", DllStructGetPtr($Struct)) If @error Then Return 0 Else Return $Ret EndIf Else MsgBox(16, "_Vista_ApplyGlassArea", "Area specified is not an array!") EndIf EndIf EndFunc ;==>_Vista_ApplyGlassArea ; #FUNCTION#;=============================================================================== ; ; Name...........: _Vista_EnableBlurBehind ; Description ...: Enables the blur effect on the provided window handle. ; Syntax.........: _Vista_EnableBlurBehind($hWnd) ; Parameters ....: $hWnd - Window handle: ; Return values .: Success - No return ; Failure - Returns 0 ; Author ........: James Brooks ; Modified.......: ; Remarks .......: Thanks to komalo ; Related .......: ; Link ..........; ; Example .......; Yes ; ;;========================================================================================== Func _Vista_EnableBlurBehind($hWnd, $bColor = 0x000000) If @OSVersion <> "WIN_VISTA" Then MsgBox(16, "_Vista_ApplyGlass", "You are not running Vista!") Exit Else Const $DWM_BB_ENABLE = 0x00000001 DllStructSetData($sStruct, 1, $DWM_BB_ENABLE) DllStructSetData($sStruct, 2, "1") DllStructSetData($sStruct, 4, "1") GUISetBkColor($bColor); Must be here! $Ret = DllCall("dwmapi.dll", "int", "DwmEnableBlurBehindWindow", "hwnd", $hWnd, "ptr", DllStructGetPtr($sStruct)) If @error Then Return 0 Else Return $Ret EndIf EndIf EndFunc ;==>_Vista_EnableBlurBehind ; #FUNCTION#;=============================================================================== ; ; Name...........: _Vista_ICE ; Description ...: Returns 1 if DWM is enabled or 0 if not ; Syntax.........: _Vista_ICE() ; Parameters ....: ; Return values .: Success - Returns 1 ; Failure - Returns 0 ; Author ........: James Brooks ; Modified.......: ; Remarks .......: Thanks to BrettF ; Related .......: ; Link ..........; ; Example .......; Yes ; ;;========================================================================================== Func _Vista_ICE() $ICEStruct = DllStructCreate("int;") $Ret = DllCall("dwmapi.dll", "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($ICEStruct)) If @error Then Return 0 Else Return DllStructGetData($ICEStruct, 1) EndIf EndFunc ;==>_Vista_ICE James
    1 point
  10. Copy the exe to a local drive and execute it from there. Might be a security feature of your OS.
    1 point
  11. its a line-continuation character https://www.autoitscript.com/autoit3/docs/intro/lang_comments.htm https://msdn.microsoft.com/en-us/library/ba9sxbw4.aspx
    1 point
  12. Hi Aleph. Are you looking to use the application on a longterm basis? If you are, I would suggest using a dynamic script, and avoid hardcoding any tasks into the actual scheduler itself... You could achieve this with an ini file, Which would contain all the data for tasks such as the frequency, Time, and directory of the program to execute. The benefit of this is that you can add additional tasks to your task scheduler without having to worry about editing the source code for the scheduler itself, It also means you could build a snazzy GUI for adding/removing tasks etc, as You wouldn't need to manually add them to the script! I've written a quick example to showcase what I mean: local $ini = @workingdir & "\config.ini" local $Tasks,$TaskInfo,$OldIni iniwrite($ini,"Test1","Dir","C:\temp\test1.exe") ;Create the ini for testing purposes iniwrite($ini,"Test1","Time","12:48") while 1 if FileRead($ini) <> $OldIni then ;Check for any updates to the ini file Console(FileRead($ini)) Console($OldIni) $Tasks = IniReadSectionNames($ini) ;Gathers each section name from ini (the identifier used per task in this example) $OldIni = FileRead($ini) ;Stores Entire contents of Ini to variable (Cheap and ugly update check on the config) if IsArray($TaskInfo) then ;Avoid ReDim Errors by checking if array exists before declaration ReDim $TaskInfo[Ubound($Tasks)][4] Else Dim $TaskInfo[Ubound($Tasks)][4] EndIf For $i = 0 to uBound($Tasks) - 1 ; For Loop to gather all task data for each task into an array $TaskInfo[$i][0] = $Tasks[$i] $TaskInfo[$i][1] = iniRead($ini,$Tasks[$i],"Dir","") $TaskInfo[$i][2] = iniRead($ini,$Tasks[$i],"Time","") $TaskInfo[$i][3] = False ;Flag to ensure only run once Next EndIf For $x = 0 to Ubound($TaskInfo,1) - 1 ;For loop to check if any tasks are to be run. if @HOUR & ":" & @MIN = $TaskInfo[$x][2] and $TaskInfo[$x][3] == False Then Run($TaskInfo[$x][1]) ; Run the task using the Directory value stored in the config file $TaskInfo[$x][3] = True ; Set the run flag to true for this task EndIf Next WEnd This application, albeit very basic, will run any files mentioned in the config.ini. If you haven't tried using the native ini functions, I would really suggest playing with them, as they're really easy to use... I certainly haven't looked back. Just a suggestion - Javi
    1 point
  13. Awesome! I updated it for latest AutoIt (some minor tweaks), I suggest a little error checking. #include <windowsconstants.au3> #Include <GuiConstants.au3> #Include <GuiEdit.au3> #Include <date.au3> opt("GUIOnEventMode", 1) Demo() ;------------------------------------------------------------------------------------------------------ ;- C O N S O L E D E M O ;------------------------------------------------------------------------------------------------------ Func Demo() Global $ConsoleID=0 $ConsoleID = ConsoleWinCreate(-1, -1, 638, 326, "Age Demo...", "Starting demo..." & @CRLF, True) $answer1 = ConsoleWinInput($ConsoleID, "Please input your Year of Birth (example.. 1985) ?", 15) $Vanswer1 =ConsoleWinVerify($ConsoleID, $answer1, "Please input your Year of Birth (example.. 1985) ?", True, 4, 4) ConsoleWinWrite($ConsoleID, "OK.. " & @CRLF, 30, 1) $answer2 = ConsoleWinInput($ConsoleID, "Please input your Month of Birth (example.. 3 = March) ?", 45) $Vanswer2 =ConsoleWinVerify($ConsoleID, $answer2, "Please input your Month of Birth (example.. 3 = March) ?", True, 1, 2) ConsoleWinWrite($ConsoleID, "Good.. " & @CRLF, 60, 1) $answer3 = ConsoleWinInput($ConsoleID, "Please input your Day of Birth (ex.. 22) ?" , 75) $Vanswer3 =ConsoleWinVerify($ConsoleID, $answer3, "Please input your Month of Birth (example.. 22) ?", True, 1, 2) ConsoleWinWrite($ConsoleID, "Great!.. Please wait while i calculate your age..." & @CRLF, 90, 1) Sleep(1000) ConsoleWinWrite($ConsoleID, " You have been alive " & _DateDiff( 'd',$Vanswer1 &"/"& $Vanswer2 &"/"& $Vanswer3,_NowCalc()) & " days!" & @CRLF, 100, 1) Sleep(5000) ConsoleWinWrite($ConsoleID, "Example: Clearing console in five seconds...Thanks Valuater 8) ") Sleep(5000) ConsoleWinClear($ConsoleID) ConsoleWinWrite($ConsoleID, "Demo finished! Exiting in five seconds...") Sleep(5000) Exit EndFunc ;------------------------------------------------------------------------------------------------------ ;- C O N S O L E L I B R A R Y ;------------------------------------------------------------------------------------------------------ ;=============================================================================== ; Description: Create a Window console to display status text information with history ; Parameter(s): $x - x position of the window ; $y - y position of the window ; $width - Optional - Window width ; $height - Optional - Window height ; $Title - Optional - Console Window title ; $text - Optional - Initial text to display. ; $CreateProgress - Optional - Create Progress (True/False) ; $BgColor - Optional - background color ; $FgColor - Optional - Foreground color ; $Transparency - Optional - Transparency (0=Invisible, 255=Visible) ; $LogFile - Optional - File to log all console text ; Requirement(s): None ; Return Value(s): The Console ID ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinCreate($x, $y, $width=638, $height=126, $Title="Console", $Text="", $CreateProgress=False, $BgColor=0xFFFFFF, $FgColor=0xFF0000, $Transparency=255, $LogFile="") Dim $Console[4] If $Text <> "" Then $Text=$Text & @CRLF $Console[0] = GuiCreate($Title, $width, $height, $x, $y, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) GUISetOnEvent($GUI_EVENT_CLOSE, "ConsoleWinExitEvent") If $CreateProgress Then $height -= 20 $Console[1] = GuiCtrlCreateEdit($Text, 0, 0, $width-1, $height-1, BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL)) GUICtrlSetBkColor($Console[1], $BgColor) GUICtrlSetColor($Console[1], $FgColor) GUICtrlSetResizing($Console[1], $GUI_DOCKBORDERS) GUICtrlSetFont($Console[1], 8, 400, 0, "Courrier New") $Console[2] =0 If $CreateProgress Then $Console[2] = GUICtrlCreateProgress(0, $height+5, $width-1, 12) if $Transparency<255 Then WinSetTrans($Console[0], "", $Transparency) DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $Console[0], "int", 300, "long", 0x00080000) GuiSetState(@SW_SHOW, $Console[0]) $Console[3] = $LogFile Sleep(50) Return $Console EndFunc ;=============================================================================== ; Description: Create a Widget console to display status text information with history ; Parameter(s): $gui - Gui window to include widget ; $x - x position of the Widget ; $y - y position of the Widget ; $width - Optional - Widget width ; $height - Optional - Widget height ; $Title - Optional - Console Window title ; $text - Optional - Initial text to display. ; $CreateProgress - Optional - Create Progress (True/False) ; $BgColor - Optional - background color ; $FgColor - Optional - Foreground color ; $LogFile - Optional - File to log all console text ; Requirement(s): None ; Return Value(s): The Console ID ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleCreate($gui, $x, $y, $width=638, $height=126, $Text="", $CreateProgress=False, $BgColor=0xFFFFFF, $FgColor=0xFF0000, $LogFile="") Dim $Console[4] If $Text <> "" Then $Text=$Text & @CRLF $Console[0] = $gui If $CreateProgress Then $height -= 20 $Console[1] = GuiCtrlCreateEdit($Text, $x, $y, $width-1, $height-1, BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL)) GUICtrlSetBkColor($Console[1], $BgColor) GUICtrlSetColor($Console[1], $FgColor) GUICtrlSetResizing($Console[1], $GUI_DOCKBORDERS) GUICtrlSetFont($Console[1], 8, 400, 0, "Courrier New") $Console[2] =0 If $CreateProgress Then $Console[2] = GUICtrlCreateProgress($x, $y+$height+5, $width-1, 12) $Console[3] = $LogFile Return $Console EndFunc Func ConsoleWinExitEvent() GUIDelete(@GUI_WinHandle) EndFunc Func ConsoleWinQuit() Exit EndFunc ;=============================================================================== ; Description: Close the Console ; Parameter(s): $ConsoleID - The console ID ; Requirement(s): None ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinClose($ConsoleID, $nAnimate = False) If UBound($ConsoleID) < 4 Then Return SetError(1) GUIDelete($ConsoleID[0]) If $nAnimate Then DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $ConsoleID[0], "int", 400, "long", 0x00090000) EndIf $ConsoleID[0] = 0 $ConsoleID[1] = 0 $ConsoleID[2] = 0 EndFunc ;=============================================================================== ; Description: Change the title of Console ; Parameter(s): $ConsoleID - The console ID ; $Title - The new title ; Requirement(s): None ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinChangeTitle($ConsoleID, $Title) If UBound($ConsoleID) < 4 Then Return SetError(1) WinSetTitle($ConsoleID[0], "", $Title) EndFunc ;=============================================================================== ; Description: Write a message to the console ; Parameter(s): $ConsoleID - Console ID returned by ConsoleWinCreate ; $text - Text to display. ; $Progress - Optional - Progress value (0-100) ; $NoCRLF - Optional - Don't add CRLF and the end of text ; $Replace - Optional - Replace last line ; Requirement(s): ConsoleWinCreate called first ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinWrite($ConsoleID, $Text, $Progress=-1, $NoCRLF=False, $Replace=False) If UBound($ConsoleID) < 4 Then Return SetError(1) If $Replace Then $string = GUICtrlRead($ConsoleID[1]) $pos = StringInStr($string, @CRLF, 0, -1) If $pos > 0 Then $pos += 1 $end = StringLen($string) _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $end) Else $pos = StringLen(GUICtrlRead($ConsoleID[1])) _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos) EndIf If StringLen(GUICtrlRead($ConsoleID[1]))>28000 Then $string = StringRight(GUICtrlRead($ConsoleID[1]), 20000) GUICtrlSetData ($ConsoleID[1], $string) EndIf If $NoCRLF = False Then $Text = $Text & @CRLF GUICtrlSetData ($ConsoleID[1], $Text, 1) If $ConsoleID[2] >0 And $Progress>=0 Then GUICtrlSetData($ConsoleID[2], $Progress) If $ConsoleID[3] <> "" Then FileWrite($ConsoleID[3], $Text) Return $ConsoleID EndFunc ;=============================================================================== ; Description: Ask for the user to input something ; Parameter(s): $ConsoleID - Console ID returned by ConsoleWinCreate ; $text - Text to display, the question. ; $Progress - Optional - Progress value (0-100) ; Requirement(s): ConsoleWinCreate called first ; Return Value(s): What user have typed. ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): $text could be an empty string ;=============================================================================== Func ConsoleWinInput($ConsoleID, $Text, $Progress=-1) If UBound($ConsoleID) < 4 Then Return SetError(1) WinSetOnTop($ConsoleID[0], "", 1) WinFlash($ConsoleID[0], "", 5, 100) WinActivate($ConsoleID[0]) $string = GUICtrlRead($ConsoleID[1]) $pos = StringLen($string) _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos) GUICtrlSetData ($ConsoleID[1], $Text, 1) GUICtrlSetStyle($ConsoleID[1], BitOR($ES_MULTILINE, $ES_AUTOVSCROLL, $WS_HSCROLL, $WS_VSCROLL, $ES_WANTRETURN)) GUICtrlSetState($ConsoleID[1], $GUI_FOCUS) If $Text <> "" Then ; Wait for the user to input something While 1 Sleep(100) $String=GUICtrlRead($ConsoleID[1]) If StringRight($string, 2) = @CRLF Then ExitLoop ; Ensure that everything is typed at the end of edit control $pos = StringLen($String) _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos) WEnd $pos = StringInStr($string, $Text, 0, -1) If $pos >0 Then $pos += StringLen($Text) Else $str = $string ; Wait for the user to input something While 1 Sleep(100) $String=GUICtrlRead($ConsoleID[1]) If StringRight($string, 2) = @CRLF And $string <> $str Then ExitLoop ; Ensure that everything is typed at the end of edit control $pos = StringLen($String) _GUICtrlEdit_SetSel($ConsoleID[1], $pos, $pos) WEnd $pos = StringInStr(StringLeft($string, StringLen($string)-2), @CRLF, 0, -1) If $pos > 0 Then $pos += 1 EndIf $string = StringMid($string, $pos) $string = StringLeft($string, StringLen($string)-2) GUICtrlSetStyle($ConsoleID[1], BitOR($ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL,$WS_HSCROLL,$WS_VSCROLL)) If $ConsoleID[2] >0 And $Progress>=0 Then GUICtrlSetData($ConsoleID[2], $Progress) WinSetOnTop($ConsoleID[0], "", 0) Return $string EndFunc ;=============================================================================== ; Description: Set progress value of the console ; Parameter(s): $ConsoleID - The console ID ; $Value - The new value to set ; $min - Optional - The minimum value possible ; $max - Optional - The maximum value possible ; Requirement(s): None ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleSetProgress($ConsoleID, $value, $min=0, $max=100) If UBound($ConsoleID) < 4 Then Return SetError(1) $percent = ($value-$min)*100 If $percent <0 Then $percent = 0 $percent /= ($max-$min) If $ConsoleID[2] >0 Then GUICtrlSetData($ConsoleID[2], $percent) EndFunc ;=============================================================================== ; Description: Clear the console ; Parameter(s): $ConsoleID - The console ID ; Requirement(s): None ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinClear($ConsoleID) If UBound($ConsoleID) < 4 Then Return SetError(1) GUICtrlSetData ($ConsoleID[1], "") If $ConsoleID[2] >0 Then GUICtrlSetData($ConsoleID[2], 0) If $ConsoleID[3] <> "" Then FileDelete($ConsoleID[3]) EndFunc ;=============================================================================== ; Description: Flash the console ; Parameter(s): $ConsoleID - The console ID ; Requirement(s): None ; Return Value(s): None ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleFlash($ConsoleID) If UBound($ConsoleID) < 4 Then Return SetError(1) WinFlash($ConsoleID[0], "", 5, 100) EndFunc ;=============================================================================== ; Description: Save the content of the console to a file ; Parameter(s): $ConsoleID - The console ID ; $FileName - The filename used to save ; Requirement(s): None ; Return Value(s): Write status, same as FileWrite ; Author(s): Jerome DERN (jerome "at" dern "dot" fr) ; Note(s): None ;=============================================================================== Func ConsoleWinSave($ConsoleID, $FileName) If UBound($ConsoleID) < 4 Then Return SetError(1) $string = GUICtrlRead($ConsoleID[1]) Return FileWrite($FileName, $string) EndFunc ;=============================================================================== ; Description: Ask for the user to verify input something ; Parameter(s): $ConsoleID - Console ID returned by ConsoleWinCreate ; $VAns - info to verify ; $Text - Text to display, the question. ; $VNum - Optional - to verify an Intreger ; $VMin - Optional - Minimum length of string ; $VMax - Otional - Maximum length of string ; Requirement(s): ConsoleWinCreate available and ConsoleWinInput called first ; Return Value(s): What user has typed. ; Author(s): Jerome DERN (jdern "at" free "dot" fr) ; Co - Author Valuater ; Note(s): $Text may not be an empty string ;=============================================================================== Func ConsoleWinVerify($ConsoleID, $VAns, $Text, $VNum = False, $VMin = 1, $VMax = 1000) While 1 ConsoleWinWrite($ConsoleID, "You have answered: " & $VAns) $VLen = StringLen($VAns) If $VNum And Int($VAns) > 0 And $VLen >= $VMin And $VLen <= $VMax Then If ConsoleWinInput($ConsoleID, 'Is this Correct? "Y" or "N" ') = "y" Then Return $VAns ElseIf Not $VNum And $VLen >= $VMin And $VLen <= $VMax Then If ConsoleWinInput($ConsoleID, 'Is this Correct? "Y" or "N" ') = "y" Then Return $VAns EndIf $VAns = ConsoleWinInput($ConsoleID, $Text) Sleep(10) WEnd EndFunc
    1 point
×
×
  • Create New...