-
Posts
34 -
Joined
-
Last visited
Everything posted by MvL
-
Hi, did you ever try the following in Excel? Sub Macro1() ' ' Macro1 Macro ' ' Selection.SpecialCells(xlCellTypeConstants, 23).Select End Sub When you translate this selection into AutoIt, followed by the construct For $cell in $oExcel.Application.Selection Next it can speed up your code for looping over cells when no formula's are involved, only constants, because empty cells are skipped. And, at the same time, you have control over each $cell object, In addtion, you can add Selection.SpecialCells(xlCellTypeVisible).Select to skip hidden rows in the selection. Together, they can be faster than reading data from an Excel worksheet into arrays using the Range().Value construct. Kind regards, MvL
-
Perhaps it is an idea to explain at one place in the help, how the properties can be found ? I use the Excel Visual Basic macro recorder (so I found how you must activate an Excel Window after ObjGet() when another Excel Winow has the focus) or directly in the Visual Basic Editor window by entering a dot after the objectname, and than choosing the method from the call tip drop down list, and again, to the lowest level of methods. Sometimes you have to use in AutoIt the $oExcel.Application expression to go up to the Excel application level sometimes directly $oExcel to stay on the Workbook level.
-
Ok, much obliged.
-
Sorry, - and then opened the workbook in Excel (went Ok) should be - and then opened the workbook in the AutoIt script using ObjGet() (this went Ok)
-
First: Ok, but when I was still editing a cell in the .xls (in the formula bar of using F2) and then opened the workbook in Excel (went Ok) and then tried to do something with the workbook, only at that moment I got a message 'The requested action with this object has failed'. It happened to me several times, it is not the code that was in error. Below is put a piece of code, to show how I prevented the message ''The requested action with this object has failed'' from the Excel error handling function from firing, and check on this specific error. Second: I don't want my script to behave unexpected, and autosave on a .xls that is stored on a network disc often takes a lot of time, leaving me wondering why that is. So I disable the autosave, before I run. Third: Yes, this is much the same, but when I have al long run, I sometimes want to see the progress (I update my .xls in the run), so I start with a minimized window, and I can restore or maximize the window to 'be in touch', and minizmize it back again for speed. With ScreenUpdate = False, I don't have that option. Piece of code to find out that the .xls is Not Ready AutoItSetOption("MustDeclareVars", 1) ; 0=No, 1=Variables must be declared. Local $x_oMyError Local $o_Result, $PathArr, $ExcelFilename Local $s_string = "C:\yy.xls" ; Already open, or to be opened. $x_oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") ; Initialize a COM error handler $o_Result = ObjGet($s_string) If @error Then MsgBox(4096, "Error", @error) Else If Not IsObj($o_Result) Then MsgBox(4096, "Error in .xls", $s_string & " does not exist") Else If Not $o_Result.Application.Ready Then MsgBox(4096, "Error", "The Excel Application has not started, Excel is not ready because you are editing in a cell.") Exit EndIf $o_Result.Windows(1).Visible = 1; Set the worksheet in the workbook visible $o_Result.Application.Visible = 1; Set the application visible $PathArr = StringSplit($s_string, "\") $ExcelFilename = $PathArr[$PathArr[0]] If $o_Result.Application.Activewindow.Caption <> $ExcelFilename Then $o_Result.Application.Windows($ExcelFilename).Activate ; point to this Excel file EndIf EndIf EndIf Exit
-
Ok nice, you might also want to consider the following, regards. ; Check if Excel is installed and if the Excel workbook is ready to run. If Not $o_Result.Application.Ready Then MsgBox(4096, "Error", "The Excel Application has not installed, or Excel is not ready because you are editing in a cell.") Exit EndIf ; Prevent AutoSave disturbance during the AutoIt - run If $o_Result.EnableAutoRecover Then $o_Result.EnableAutoRecover = False MsgBox(4096, "Autorecover", "The AutoRecover will be disabled for this Excel workbook", 5) ; show for a number of seconds EndIf ; Minimize the workbook, to speed up the AutoIt - run $o_Result.Application.WindowState = -4140 ; xlMinimized
-
If $o_Result.Application.Activewindow.Caption <> $ExcelFilename Then $o_Result.Application.Windows($ExcelFilename).Activate EndIf This snippet activates the correct Excel Window of the Excel object, similar to the additional code I offered for _ExcelBookAttach() in the topic 'Excel Book Attach Problem' In all: AutoItSetOption("MustDeclareVars", 1) ; 0=No, 1=Variables must be declared. Local $o_Result, $PathArr, $ExcelFilename Local $s_string = "C:\yy.xls" ; Already open, or to be opened. $o_Result = ObjGet($s_string) If @error Or Not IsObj($o_Result) Then MsgBox(4096, "Error on Workbook", $s_string & " does not exist") Else $o_Result.Windows(1).Visible = 1; Set the worksheet in the workbook visible $o_Result.Application.Visible = 1; Set the application visible $PathArr = StringSplit($s_string, "\") $ExcelFilename = $PathArr[$PathArr[0]] If $o_Result.Application.Activewindow.Caption <> $ExcelFilename Then $o_Result.Application.Windows($ExcelFilename).Activate ; point to this Excel file EndIf EndIf Exit
-
I used the following, letting Excel activate the attached window. Before, in Excel.au3 Func _ExcelBookAttach($s_string, $s_mode = "FilePath") Local $o_Result If $s_mode = "filepath" Then $o_Result = ObjGet($s_string) If Not @error And IsObj($o_Result) Then Return $o_Result EndIf EndIf ... Into Func _ExcelBookAttach($s_string, $s_mode = "FilePath") Local $o_Result, $PathArr, $ExcelFilename If $s_mode = "filepath" Then $o_Result = ObjGet($s_string) If Not @error And IsObj($o_Result) Then $PathArr = StringSplit($s_string, "\") $ExcelFilename = $PathArr[$PathArr[0]] ;MsgBox(4096, $ExcelFilename, $o_Result.Application.Activewindow.Caption) If $o_Result.Application.Activewindow.Caption <> $ExcelFilename Then $o_Result.Application.Windows($ExcelFilename).Activate EndIf Return $o_Result EndIf EndIf ... Excel activates the attached window.
-
Split the DOM load (highlighted and as attachment)
MvL replied to MvL's topic in AutoIt Example Scripts
[autoit] ; The results that will be shown are: ; 6 rows |Ticked <room>'s|Ind.| Dots |<parent> with |<box>'s |Next |First <child> with ; |with /stripped value(s)/ /stripped value/ |/value, not stripped/ |levels |/value, stripped/ ; [1] |/left/ |3 |...x |<trunk>/big/ |/bread/ |0 | ; [2] |/left/ |3 |...x |<trunk>/big/ |/butter/ |0 | ; [3] |/left/ |3 |...x |<trunk>/big/ |/~~cup / |1 |<box>/spoon/ ; [4] |/left/ |4 |....x|<box>/cup/ |/spoon/ |0 | ; [5] |/left/ |3 |...x |<trunk>/big/ |/ mystery / |1 | ; [6] |/right/ |3 |...x |<trunk>/small/ |/saucer/ |0 |<color>/blue/ ; Further analysed that is performed in the While loop of the main scripts, renders: ; / mystery / ;as result of the selection: $eval = _ "$arrFilteredNodesValues[$iSelected] = '/left/' "& _ " And $arrParentNodeAndValue[$iSelected] = '<trunk>/big/' " & _ " And $arrNextLevels[$iSelected] > 0 " ; Here's an additional function. Func node($var) Local $arr $arr = StringSplit($var, '<>', 0) if $arr[0] = 1 Then Return '' Else Return '<' & $arr[2] & '>' EndIf EndFunc ;==>node [autoit] -
Split the DOM load (highlighted and as attachment)
MvL replied to MvL's topic in AutoIt Example Scripts
Thank you for the assistance. -
Split the DOM load (highlighted and as attachment)
MvL replied to MvL's topic in AutoIt Example Scripts
; The short version, using include files, is: ; (You can copy this function to a new name, and alter the Filter logic) Func XML_split_the_DOM_load($_sContent, $_sSearchTag, $_sFilterNodeName, $_bFilterIsEnclosed, $_aKeepFilteredValues, _ ByRef $_aFilteredNodesValues, ByRef $_aIndNr, ByRef $_aIndStr, ByRef $_aParentNodeAndValue, ByRef $_aResult, _ ByRef $_aNextLevels, ByRef $_aFirstChild, _ $_showResults, $_firstTime = True, $_iPointer = 1) Local $nodeName, $nodeValue, $nodeValueTicked #include '..XMLincludePartsXMLinludePart1.au3' ; Filter logic: $nodeValueTicked = ($_sFilterNodeName <> '') And ($nodeName == $_sFilterNodeName) ; Case sensitive If $nodeValueTicked Then _ArrayAdd($_aKeepFilteredValues, StringStripWS($nodeValue, 3)) ; 3 = stripped from leading and trailing CR, spaces. $_aKeepFilteredValues[0] = $_aKeepFilteredValues[0] + 1 EndIf #include '..XMLincludePartsXMLinludePart2.au3' XML_split_the_DOM_load($_sContent, $_sSearchTag, $_sFilterNodeName, $_bFilterIsEnclosed, $_aKeepFilteredValues, _ $_aFilteredNodesValues, $_aIndNr, $_aIndStr, $_aParentNodeAndValue, $_aResult, $_aNextLevels, $_aFirstChild, _ $_showResults, False, $_iPointer) #include '..XMLincludePartsXMLinludePart3.au3' Return $_MoreLevels EndFunc ;==>XML_split_the_DOM_load ; The long version is: Func XML_split_the_DOM_load($_sContent, $_sSearchTag, $_sFilterNodeName, $_bFilterIsEnclosed, $_aKeepFilteredValues, _ ByRef $_aFilteredNodesValues, ByRef $_aIndNr, ByRef $_aIndStr, ByRef $_aParentNodeAndValue, ByRef $_aResult, _ ByRef $_aNextLevels, ByRef $_aFirstChild, _ $_showResults, $_firstTime = True, $_iPointer = 1) Local $nodeName, $nodeValue, $nodeValueTicked ; Begin #include '..XMLincludePartsXMLinludePart1.au3' Local $_nodeNameLength, $_conditionLevels = -1 Local $_aOccurences, $_nrOccurences, $_arrShowMax = 40, $_arrShow[$_arrShowMax][8], $_nrToShow, $_startTime, $_diffTime Local $_waarde, $_nrSubLoops, $_nrOfNextLevels, $_MoreLevels = False Local $_aSplit, $_iLoop, $_arrWaarde[3], $_iWaarde Local $_sMatchSearchTag, $_sMatchSearchTagLen, $_searchNoDelim, $_blok, $_stop, $_stopLen, $_sMatchSearchTagFound Local $_ParentNodeName, $_ParentNodeNameLen, $_ParentNodeValue, $_sFirstChild, $_FirstChildLen Local $_sMatchFilterNode, $_sMatchFilterNodeLen, $_endFilter, $_endFilterLen Local $_iPointerDiff, $_aPointerDiff[2], $_iDots Local $_str, $_arrTag Local $_arr1[1] ; Initial arrays Const $_caseSense = 2 ; preferably 2 not case sensitive, using a basic/faster comparison ;0 = not case sensitive, using the user's locale (default) ;1 = case sensitive If (Stringleft($_sSearchTag, 1) <> '<') Or (StringRight($_sSearchTag, 1) <> '>') Then SetError(1) Return False EndIf If $_showResults Then $_startTime = _Timer_Init() $_sMatchSearchTag = StringMid($_sSearchTag, 2) ; drop the '<' $_sMatchSearchTagLen = StringLen($_sMatchSearchTag) $_searchNoDelim = StringTrimRight($_sSearchTag, 1) ; drop the '>' $_searchNoDelim = StringMid($_searchNoDelim, 2) ; drop the '<' $_blok = $_searchNoDelim & '/>' $_stop = '/'& $_searchNoDelim & '>' $_stopLen = $_sMatchSearchTagLen + 1 $_aSplit = StringSplit($_sContent, '<', 1) ; If $_firstTime Then _ArrayDisplay($_aSplit, '$_aSplit[0] ' & $_aSplit[0] & ', $_nrOccurences: '& $_nrOccurences) $_arr1[0] = 0 If $_firstTime Then $_aSplit[1] = '>' ; Remember the number of times that the tag is found for the First time in de $_sContent, to skip out of the while loop when the last occurrence is found. $_nrOccurences = $_aResult[0] ; Offset value $_aOccurences = StringSplit($_sContent, $_sSearchTag, 1) ; 1 = (for the first time) split on the whole $_sSearchTag string. $_nrOccurences = $_nrOccurences + ( $_aOccurences[0] - 1 ) $_aOccurences = StringSplit($_sContent, '<' & $_blok , 1) $_nrOccurences = $_nrOccurences + ( $_aOccurences[0] - 1 ) ; Initiate $_aIndNr = $_arr1 $_aIndStr = $_arr1 $_aParentNodeAndValue = $_arr1 $_aResult = $_arr1 $_aNextLevels = $_arr1 $_aFirstChild = $_arr1 Else $_aSplit[1] = $_sMatchSearchTag & $_aSplit[1] EndIf $_aPointerDiff[0] = 1 $_aPointerDiff[1] = 1 ; This element now points to $_aSplit[1], containing $_sSearchTag or '<>' $_iPointerDiff = 1 ; There is one pointer in the array $_aPointerDiff[] If $_firstTime Then $_aKeepFilteredValues = $_arr1 _ArrayAdd($_aKeepFilteredValues, '') $_aKeepFilteredValues[0] = 1 EndIf If ($_sFilterNodeName <> '') Then $_sMatchFilterNode = StringMid($_sFilterNodeName, 2) ; drop the '<' $_sMatchFilterNodeLen = StringLen($_sMatchFilterNode) $_endFilter = '/'& $_sMatchFilterNode $_endFilterLen = $_sMatchFilterNodeLen + 1 EndIf $_iLoop = 2 While $_iLoop <= $_aSplit[0] ; Loop over all pieces If StringLeft($_aSplit[$_iLoop], 1) == '/' Then ; '</' This one first, use the fastest comparison that is case sensitive == ; EndTag '</' $_iPointerDiff = $_iPointerDiff - 1 $_iPointer = $_iPointer - 1 ; ###################### FILTER START for EndTag '</' ############################ If ($_sFilterNodeName <> '') And $_bFilterIsEnclosed Then If StringLeft($_aSplit[$_iLoop], $_endFilterLen) == $_endFilter Then ; case sensitive ; shorten the array $_aKeepFilteredValues by 1 element. If $_aKeepFilteredValues[0] > 1 Then $_arrTag = $_arr1 $_arrTag[0] = $_aKeepFilteredValues[0] - 1 For $iTag = 1 To $_arrTag[0] _ArrayAdd($_arrTag, $_aKeepFilteredValues[$iTag]) Next $_aKeepFilteredValues = $_arrTag EndIf EndIf EndIf ; ###################### FILTER END for EndTag '</' ############################ ; EndTag '</' Else ; Begin Tag '<' $_iPointerDiff = $_iPointerDiff + 1 $_iPointer = $_iPointer + 1 If $_iPointerDiff > 0 Then If $_iPointerDiff <= $_aPointerDiff[0] Then $_aPointerDiff[$_iPointerDiff] = $_iLoop Else _ArrayAdd($_aPointerDiff, $_iLoop) $_aPointerDiff[0] = $_aPointerDiff[0] + 1 EndIf EndIf $_sMatchSearchTagFound = StringLeft($_aSplit[$_iLoop], $_sMatchSearchTagLen) == $_sMatchSearchTag If Not $_sMatchSearchTagFound And Not (StringLeft($_aSplit[$_iLoop], $_sMatchSearchTagLen + 1) == $_blok) Then ; '<' If StringInStr($_aSplit[$_iLoop], '/>') Then ; /> immediately ends the tag $_iPointerDiff = $_iPointerDiff - 1 $_iPointer = $_iPointer - 1 Else ; begin simple '<' $_nodeNameLength = StringInStr($_aSplit[$_iLoop], '>') $nodeName = '<' & StringLeft($_aSplit[$_iLoop], $_nodeNameLength) $nodeValue = StringMid ($_aSplit[$_iLoop], $_nodeNameLength + 1) ; simple '<' ; End #include '..XMLincludePartsXMLinludePart1.au3' ; ######## FILTER LOGIC ######## $nodeValueTicked = ($_sFilterNodeName <> '') And ($nodeName == $_sFilterNodeName) ; Case sensitive If $nodeValueTicked Then _ArrayAdd($_aKeepFilteredValues, StringStripWS($nodeValue, 3)) ; 3 = stripped from leading and trailing CR, spaces. $_aKeepFilteredValues[0] = $_aKeepFilteredValues[0] + 1 EndIf ; ######## FILTER LOGIC ######## ; Begin #include '..XMLincludePartsXMLinludePart2.au3' EndIf ; end simple '<' Else ; $_sMatchSearchTagFound Or ( StringLeft($_aSplit[$_iLoop], $_sMatchSearchTagLen + 1) == $_blok) $_nrOfNextLevels = 0 $_waarde = '' $_arrWaarde[1] = '' If $_sMatchSearchTagFound Then $_waarde = StringMid($_aSplit[$_iLoop], $_sMatchSearchTagLen + 1) ; the value is the remainder, up to the next < $_arrWaarde[1] = $_waarde ; don't strip the value StringStripWS($_waarde, 3) ; stripped from CR and 3 = stripped from leading and trailing WhiteSpaces $_iLoop = $_iLoop + 1 $_nrSubLoops = 0 $_nrOfNextLevels = 0 $_sFirstChild = '' While $_iLoop <= $_aSplit[0] ; Loop over all pieces If StringLeft($_aSplit[$_iLoop], $_sMatchSearchTagLen + 1) == $_stop Then ; looking for the stop-tag. If $_nrSubLoops = 0 Then ExitLoop $_nrSubLoops = $_nrSubLoops - 1 Else $_arrTag = StringSplit($_aSplit[$_iLoop], '>', 1) ; We are in the loop for $_sMatchSearchTagFound, and on the next tag. The stop-tag is not found yet. ; So we have a child node If ($_sFirstChild = '') _ ; First child node And (StringRight($_arrTag[1], 1) <> '/') Then ; not an end tag $_sFirstChild = '<' & $_arrTag[1] & '>' If $_arrTag[0] > 1 Then ; There is a remainder behind the '>' of the child node $_sFirstChild = $_sFirstChild & '/'& StringStripWS($_arrTag[2], 3) & '/' EndIf EndIf If $_arrTag[1] == $_searchNoDelim Then $_nrSubLoops = $_nrSubLoops + 1 $_MoreLevels = True If $_nrSubLoops > $_nrOfNextLevels Then $_nrOfNextLevels = $_nrSubLoops EndIf EndIf EndIf $_waarde = $_waarde & '<' & $_aSplit[$_iLoop] $_iLoop = $_iLoop + 1 Wend EndIf $_arrTag = StringSplit($_waarde, '>', 1) ; The value after any last tag, in $_waarde the next level string $_arrWaarde[2] = $_arrTag[$_arrTag[0]]; Don't strip the value StringStripWS($_arrTag[$_arrTag[0]], 3) ; stripped from CR and 3 = stripped from leading and trailing WhiteSpaces $_iWaarde = 0 While $_iWaarde < 2 $_iWaarde = $_iWaarde + 1 $_iDots = $_iPointer - 2 ; ---- Add element to $_aFilteredNodesValues[] ---- If $_aKeepFilteredValues[0] = 1 Then _ArrayAdd($_aFilteredNodesValues, '') Else _ArrayAdd($_aFilteredNodesValues, '/' & _ArrayToString($_aKeepFilteredValues, '/', 2, $_aKeepFilteredValues[0]) & '/') EndIf $_aFilteredNodesValues[0] = $_aFilteredNodesValues[0] + 1 ; ---- Add element to $_aIndNr[] ---- _ArrayAdd($_aIndNr, $_iDots) $_aIndNr[0] = $_aIndNr[0] + 1 ; ---- Add element to aIdentStr[] ---- $_str = '' If $_iDots > 0 then For $_j = 1 to $_iDots $_str = $_str & '.' Next _ArrayAdd($_aIndStr, $_str & 'x' ) Else For $_j = 1 to Abs($_iDots ) $_str = $_str & '-' Next _ArrayAdd($_aIndStr, 'x' & $_str ) Endif $_aIndStr[0] = $_aIndStr[0] + 1 ; ---- Add element to Parent nodes[] ---- If $_iPointerDiff >= 2 then $_str = $_aSplit[$_aPointerDiff[$_iPointerDiff - 1]] $_ParentNodeNameLen = StringInStr($_str, '>') $_ParentNodeName = '<' & StringLeft($_str, $_ParentNodeNameLen) $_ParentNodeValue = StringStripWS(StringMid($_str, $_ParentNodeNameLen + 1), 3) ; nodes and there values are anchors for filtering. The value's must be stripped from CR and 3 = stripped from leading and trailing WhiteSpaces _ArrayAdd($_aParentNodeAndValue, $_ParentNodeName & '/' & $_ParentNodeValue & '/') Else _ArrayAdd($_aParentNodeAndValue, '<>' ) Endif $_aParentNodeAndValue[0] = $_aParentNodeAndValue[0] + 1 ; ---- Add element to $_aResult[] ---- _ArrayAdd($_aResult, '/' & $_arrWaarde[$_iWaarde] & '/') $_aResult[0] = $_aResult[0] + 1 ; ---- Add element to $_aNextLevels[] ---- _ArrayAdd($_aNextLevels, $_nrOfNextLevels) $_aNextLevels[0] = $_aNextLevels[0] + 1 ; ---- Add element to $_aFirstChild[] ---- If ($_iWaarde = 1) Then _ArrayAdd($_aFirstChild, $_sFirstChild) Else _ArrayAdd($_aFirstChild, '') EndIf $_aFirstChild[0] = $_aFirstChild[0] + 1 If $_nrOfNextLevels = 0 Then ExitLoop If ($_iWaarde = 2) Then ExitLoop $_sContent = $_waarde ; to make the next call look similar to the first call ; End #include '..XMLincludePartsXMLinludePart2.au3' XML_split_the_DOM_load($_sContent, $_sSearchTag, $_sFilterNodeName, $_bFilterIsEnclosed, $_aKeepFilteredValues, _ $_aFilteredNodesValues, $_aIndNr, $_aIndStr, $_aParentNodeAndValue, $_aResult, $_aNextLevels, $_aFirstChild, _ $_showResults, False, $_iPointer) ; Begin #include '..XMLincludePartsXMLinludePart3.au3' ; $_iPointer has been called by value (not ByRef) so it's value is local, and has not been changed by XML_split_the_DOM_load() If ($_iWaarde = 1) And ($_arrWaarde[2] = '') Then ExitLoop $_nrOccurences = $_nrOccurences + 1 ; For ($_arrWaarde[2] <> '') WEnd $_iPointerDiff = $_iPointerDiff - 1 $_iPointer = $_iPointer - 1 If $_firstTime and ($_aResult[0] = $_nrOccurences) Then ExitLoop ; For efficiency. EndIf ; End of begin Tag '<' EndIf ; End of end Tag '</' $_iLoop = $_iLoop + 1 Wend If $_firstTime And $_showResults And (Eval('C_ActionflowMode') <> 9 ) Then $_diffTime = _Timer_Diff($_startTime) $_arrShow[0][0] = $_aResult[0] & ' *' $_arrShow[0][1] = 'Ticked ' & $_sFilterNodeName & '''s /value(s), stripped/' $_arrShow[0][2] = 'Indents' $_arrShow[0][3] = 'Dots' $_arrShow[0][4] = '<parent> with /value, stripped ' $_arrShow[0][5] = $_sSearchTag & '''s /value, not stripped/' $_arrShow[0][6] = 'Next levels' $_arrShow[0][7] = 'First <child> with /value, stripped/' $_nrToShow = $_aResult[0] If $_nrToShow > $_arrShowMax - 1 Then $_nrToShow = $_arrShowMax - 1 MsgBox(4096, '', 'Only ' & $_nrToShow & ' of the ' & $_aResult[0] & ' results are shown.') EndIf For $_i = 1 to $_nrToShow $_arrShow[$_i ][0] = '' $_arrShow[$_i ][1] = $_aFilteredNodesValues[$_i ] $_arrShow[$_i ][2] = $_aIndNr[$_i ] $_arrShow[$_i ][3] = $_aIndStr[$_i ] $_arrShow[$_i ][4] = $_aParentNodeAndValue[$_i ] $_arrShow[$_i ][5] = $_aResult[$_i ] $_arrShow[$_i ][6] = $_aNextLevels[$_i ] $_arrShow[$_i ][7] = $_aFirstChild[$_i ] Next _ArrayDisplay($_arrShow, $_diffTime & ' msec.', $_nrToShow) Endif ; End #include '..XMLincludePartsXMLinludePart3.au3' Return $_MoreLevels EndFunc ;==>XML_split_the_DOM_load -
Split the DOM load (highlighted and as attachment)
MvL replied to MvL's topic in AutoIt Example Scripts
; #FUNCTION# ====================================================================================================== ; Name...........: XML_split_the_DOM_load ; Description ...: Parser for a XML file by splitting it's DOM load by a specific tag. ; . Parsing nesting tag's is supported. ; . Parse and filter is supported. ; . The results are returned in six ByRef arrays parameters, ; to be further analysed in a While loop over the index of the array(s). ; . The DOM load is assumed to be valid: ; Besides a rudimentary check on the presence of at least one '<' and one '>' ; there is no additional check on consistent use of '<' '>' or '</' '>' or '<' '/>' ; In other words: The split always succeeds. ; Syntax.........: .. ; Parameters ....: ; $_sContent : The XML content to split. ; $_sSearchTag : The search tag, with opening < and closing > ; $_sFilterNodeName : The node names of which the values ar ticked in $_aFilteredNodesValues ; $_bFilterIsEnclosed : False: the values in aray $_aFilteredNodesValues are allowed to run wide. ; $_aKeepFilteredValues: : Array reserved for in-line filtering. ; ; Six resulting arrays ByRef, to be declared as input with one element, syntax: $_aName[1]. ; The number of elements is dynamically expanended. ; The five arrays keep up with the same number of elements. ; This number is stored in array element 0. ; Trim Whitespaces (leading and trailing) includes Chr(9) thru Chr(13) which are ; HorizontalTab, LineFeed, VerticalTab, FormFeed, and CarriageReturn. ; Whitespace also includes the null string ( Chr(0) ) and the standard space ( Chr(32) ). ; ByRef $_aFilteredNodesValues: The array with the ticked nodes /values/, without white spaces. ; ByRef $_aIndNr : Array: The number of open parent-nodes (for each result). ; ByRef $_aIndStr : Array: String of dots, visualizing the number of open parent-nodes (for each result). ; ByRef $_aParentNodeAndValue : Array: The name of the <parent-node> and /value/, without white spaces. ; ByRef $_aResult : Array: Each split result. ; ByRef $_aNextLevels : Array: The depth of tags of the samen search-tags (for each result). ; ByRef $_aFirstChild : Array: The first child-node and value, after the search-tag (for each result). ; ; $_showResults : Indication to show all results and arrays. ; $_firstTime = True : Boolean, should not be added to the function call, is for handling extra levels. ; $_iPointer = 1 : Integer, should not be added to the function call, is for handling extra levels. ; Global $_C_ActionflowMode : Optional. 0 = interactive, 9 = unattended. ; ; Return values .: $_MoreLevels: True when array elements contain next levels of search tags. ; Six arrays : The five arrays above are both for input ($_firstTime = True) as output. ; @error : If the $_sSearchTag has no delimeters < or > then the @error is set to 1. ; ; Author ........: Martin van Leeuwen ; Modified.......: 19 okt 2012 -
Split the DOM load (highlighted and as attachment)
MvL replied to MvL's topic in AutoIt Example Scripts
; Filename: XML split the DOM load.au3 ; Author: Martin van Leeuwen ; Date: 15-okt-2012 #include '..XMLincludePartsXML_split_the_DOM_load.au3' #include <Array.au3> #include <Timers.au3> ; For measuring script performance Global $showResults, $FileName, $Id, $sContent, $sSearchTag, $sFilterNodeName, $booleanFilterIsEnclosed Global $arrKeepFilteredValues[1] ; Reserved variable Global $arrFilteredNodesValues[1], $arrIndNr[1], $arrIndStr[1], $arrParentNodeAndValue[1], $arrResult[1], _ $arrNextLevels[1], $arrFirstChild[1] Global $isLeveled, $iSelected, $eval, $occurence Global $StartTime Global $askFile $askFile = False If $AskFile Then $FileName = @ScriptDir & '' & 'cup and saucer.xml' ; $FileName = FileOpenDialog('Open xml load file', @MyDocumentsDir & '', 'All (*.*)', 1 + 4 , $FileName) $Id = FileOpen($FileName) If $Id = -1 Then iii('Bestand niet gevonden.') Exit EndIf $sContent = FileRead($Id) FileClose($Id) $sSearchTag = '<box>' $sFilterNodeName = '<room>' ; case sensitive $booleanFilterIsEnclosed = True Else $sContent = '<house>' & _ '<room>' & _ 'left' & _ '<trunk>big' & _ '<box>bread</box>' & _ '<box>butter</box>' & _ '<box>' & _ Chr(12) & Chr(10) &'cup <box>spoon</box> mystery </box>' & _ '</trunk>' & _ '</room>' & _ '<room> right' & _ '<trunk>small' & _ '<box>saucer<color>blue </color></box>' & _ '</trunk>' & _ '</room>' & _ '</house>' $sSearchTag = '<box>' $sFilterNodeName = '<room>' ; case sensitive $booleanFilterIsEnclosed = True EndIf ; Further analysed is needed in a While loop over the index of the array(s), ; to find our expected result: 'saucer' $StartTime = _Timer_Init() $iSelected = 0 $showResults = True $eval = "$arrFilteredNodesValues[$iSelected] = '/left/' And $arrParentNodeAndValue[$iSelected] = '<trunk>/big/' And $arrNextLevels[$iSelected] > 0 " $occurence = 0 $isLeveled = _ XML_split_the_DOM_load($sContent, $sSearchTag, $sFilterNodeName, $booleanFilterIsEnclosed, $arrKeepFilteredValues, _ $arrFilteredNodesValues, $arrIndNr, $arrIndStr, $arrParentNodeAndValue, $arrResult, $arrNextLevels, $arrFirstChild, $showResults) ; Duration of the function call was: 2,5 msec If @error <> 0 Then MsgBox(4096, '', '$sSearchTag misses < or > ') ElseIf ($arrResult[0] <= 0) Then MsgBox(4096, '', 'Geen ' & $sSearchTag & ' gevonden.') Else ; Begin $sSearchTag $StartTime = _Timer_Init() While True $iSelected = $iSelected + 1 If $iSelected > $arrResult[0] Then $iSelected = 0 MsgBox(4096, '', 'Niet gevonden: ' & $eval ) ExitLoop EndIf If Execute($eval) Then $occurence = $occurence + 1 If $occurence = 2 Then ExitLoop EndIf WEnd EndIf ; End $sSearchTag If $iSelected > 0 Then MsgBox(4096, _Timer_Diff($StartTime) & ' + msec', 'Result for: ' & $eval & @CRLF & $arrResult[$iSelected]) ; saucer EndIf -
I worked out a script to split an XML string by tag. The result is put in an array. Other info like the name of the parent node that goes with a result is stored in separate arrays. The XML string represents a DOM load. The main script is:
-
XML split the DOM load ( AutoIT code is highlighted )
MvL replied to MvL's topic in AutoIt Example Scripts
Melba23, thank you, please delete this post, I want to avoid the extra coding-tags in my post. -
XML split the DOM load ( AutoIT code is highlighted )
MvL replied to MvL's topic in AutoIt Example Scripts
Look for the latest version of this post in: -
XML split the DOM load ( AutoIT code is highlighted )
MvL replied to MvL's topic in AutoIt Example Scripts
Look for the latest version of this post in: -
Hi guys, look for the latest version of this function in:
-
For $sContent = '<brp:aanschrijving><brp:voornamen>Bennie</brp:voornamen></brp:aanschrijving><brp:aanschrijving><brp:voornamen>Adam</brp:voornamen></brp:aanschrijving>' $strZoek = 'brp:aanschrijving' the result that will be shown is: [0] 2 levels|2 inspringingen|2 nodes|2 results voor <brp:aanschrijving> [1] 0|x|<<>|<brp:voornamen>Bennie</brp:voornamen> [2]||0|x|<<>|<brp:voornamen>Adam</brp:voornamen> And the content of: $arrResult[] is [0]|2 [1]|<brp:voornamen>Bennie</brp:voornamen> [2]|<brp:voornamen>Adam</brp:voornamen>
-
Hi GillesG, I wrote this XML splitter. Does this solve your problem ? The call is: Global $showResults, $sContent, $strZoek Global $arrLevel[1], $arrSpaces[1], $arrNode[1], $arrResult[1] $sContent = '<brp:aanschrijving><brp:voornamen>Bennie</brp:voornamen></brp:aanschrijving> $strZoek = 'brp:voornamen' $showResults = True TuXmlParse($sContent, $strZoek, $arrLevel, $arrSpaces, $arrNode, $arrResult, $showResults) 35_Tuned XML.au3 This results in: [1]||1|.x|<brp:aanschrijving>|Bennie
-
Hi, perhaps it is because of the small font, but the font in the example code seems to be Italic, and that makes it less readable. The general colourscheme is an improvement though.
-
Workaround: replace: $oExcel.Cells($Row, $Column).Comment.Text($str) by $oExcel.Cells($Row, $Column).value = $str $oExcel.Cells($Row, $Column).Interior.Color = 255 ; Red and add the comment marker in front of the lines: ; $oExcel.Selection.Comment.Visible = False ; $oExcel.Cells($Row, $Column).AddComment ; $oExcel.Cells($Row, $Column).Comment.Shape.Width = 250 ; $oExcel.Cells($Row, $Column).Comment.Shape.Height = 100
-
; ; =============================================================================================================================== ; Title .........: AC generate IE script v0.2.au3 ; Version : 0.2.0 ; Date : 30 november 2011 ; Language ......: English ; Description ...: Generate the AutoIT script for Internet Explorer Form elements of type "text". ; Author(s) .....: Martin van Leeuwen ; =============================================================================================================================== #include-once Opt("MustDeclareVars", 1); 0=no, 1=variables must be declared on forehand. Opt("WinTitleMatchMode", 1) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase ; DECLARATION of variables Global $IE_oBrowser Global $x_oFrames, $x_oFrame Global $x_oForms, $x_oForm, $x_oFormObjects, $x_oFormObject Global $x_oButtons, $x_oButton Global $x_oDIVs, $x_oDIV, $x_oDIVitems, $x_oDIVitem Global $x_oTables, $x_oTable, $x_oLinks, $x_oLink, $x_oImgs, $x_oImg Global $x_iNumFrames Global $x_iNumForms Global $x_iNumFormObjects Global $x_iNumButtons, $x_Button_Arr Global $x_iNumDIVs, $x_iNumDIVitems Global $x_iNumTables, $x_Table_Arr Global $x_iNumLinks Global $x_iNumImgs Global $x_oMyError Global $C_WaitForAUTsec = 4; Number of seconds to wait, before the next window of the AUT is there. ; Can be dependent on the speed of the network at any moment. #include <IE.au3> ; #include <File.au3> #include <Date.au3> #include <Array.au3> #include <Excel.au3> Global $SchermNaam = "????" Global $Transparancy = 240 Global $Array[1000][2] Global $IE_generated_script Global $IE_Title, $MarkerPos, $IE_generate_IEobjects_fileID, $NowCalcDate, $HulpString Global $IE_oBrowserFrameForm, $IE_oObj, $C_out Global $keep_ScriptLineNumber, $FileLineCount = 1 _main() Exit Func MyErrFuncViewer() ; This is my custom defined COM error handler, that is referred to in the first line ; of the _main_viewer() function. ; No error handling wanted EndFunc ;==>MyErrFuncViewer Func _main() Local $Args[1000] $x_oMyError = ObjEvent("AutoIt.Error", "MyErrFuncViewer") ; Initialize my COM error handler _IEErrorNotify(False) ; No _IEErrorNotifications wanted (IE.au3 writes diagnostic information, ; warnings and errors to the console by default). ; With <Alt>l (lower case L) you get a listbox with the functions in this .au3 ; With <Control>j , while the cursor is on the functioncall, you jump to the function code. IE_Start() IE_and_Frames_generate_a_Forms_script() IE_Ending_generate() EndFunc ;==>_main ; ++++++++++++++++++++++++++++++++++++++++++++++ IE_Start +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Func IE_Start() Local $Whnd If $CmdLine[0] >= 1 Then If $CmdLine[1] = "" Then Exit ; nothing to do. Else $SchermNaam = $CmdLine[1] EndIf Else $IE_Title = IE_Start_Find() If $IE_Title <> "" Then $SchermNaam = $IE_Title EndIf If $CmdLine[0] >= 2 Then If $CmdLine[2] = "" Then Exit ; nothing to do. Else $IE_generated_script = $CmdLine[2] EndIf EndIf $MarkerPos = StringInStr($SchermNaam, " ") If $MarkerPos > 0 Then $SchermNaam = StringMid($SchermNaam, 1, $MarkerPos - 1) $MarkerPos = StringInStr($SchermNaam, ",") If $MarkerPos > 0 Then $SchermNaam = StringMid($SchermNaam, 1, $MarkerPos - 1) If $CmdLine[0] = 0 Then $SchermNaam = InputBox("Internet Explorer Object-Viewer", "(First part of the) Title of the IE window: ", $SchermNaam) If @error = 1 Then ; The Cancel button was pushed. Exit EndIf $IE_generated_script = InputBox("Internet Explorer Object-Viewer", "Output file: ", $IE_generated_script) If @error = 1 Then ; The Cancel button was pushed. Exit EndIf $Transparancy = InputBox("Transparancy", "Transparancy (255 = Solid, 0 = Invisible): ", $Transparancy) EndIf $IE_oBrowser = _IEAttach($SchermNaam) If @error <> 0 Then ; MsgBox(4096, "AC_IE_ObjectViewer", "Error in finding screen name: " & $SchermNaam & @CRLF & "Error is: " & @error) Exit EndIf $IE_generated_script = @MyDocumentsDir & "AC_IE_generated_script " & " " & TuDateTimeStampPattern() & ".au3" ; Open the .txt file for reporting If Not _FileCreate($IE_generated_script) Then ; MsgBox(0, "Error", " Error Creating/Resetting " & $IE_generated_script & " error:" & @error) Exit EndIf $IE_generate_IEobjects_fileID = FileOpen($IE_generated_script, 2) ; 2 = Write mode (erase previous contents) If $IE_generate_IEobjects_fileID = -1 Then ; MsgBox(0, "Error", "Unable to open file: " & $IE_generated_script) Exit EndIf $NowCalcDate = _NowCalcDate() & " " & _NowTime(5) $HulpString = "; Generated script for Forms-elements and Buttons, " & $NowCalcDate & " of Web-Page: " & $SchermNaam FileWriteLine($IE_generate_IEobjects_fileID, $HulpString & @CRLF & @CRLF) EndFunc ;==>IE_Start Func IE_Start_Find() Local $var, $IEframe_Occurences, $i, $hWnd, $aClass $var = WinList() $IEframe_Occurences = 0 For $i = 1 To $var[0][0] ; Only display visible windows that have a title $hWnd = $var[$i][1] If $var[$i][0] <> "" And BitAND(WinGetState($hWnd), 2) Then ; Is visible is governed by: BitAND(WinGetState($hWnd), 2) ; MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1]) $aClass = DllCall("User32.dll", "int", "GetClassName", "hwnd", $hWnd, "str", "", "int", 4096) If $aClass[2] = "IEframe" Then Return $var[$i][0] EndIf ; MsgBox(4096, "$IEframe_Occurences: ", $IEframe_Occurences & @CR & $aClass[2] & @CR & "Title=" & $var[$i][0]) If $IEframe_Occurences > 1 Then ExitLoop 1 EndIf Next Return "" EndFunc ;==>IE_Start_Find Func TuDateTimeStampPattern() Local $Str $Str = _NowCalcDate() & " " & _NowTime(5) $Str = StringReplace($Str, "/", "-") $Str = StringReplace($Str, ":", ".") Return $Str EndFunc ;==>TuDateTimeStampPattern Func IE_Ending_generate() Local $handle, $PID, $arrxy, $i, $j, $Str, $Row, $Column FileWriteLine($IE_generate_IEobjects_fileID, @CRLF & @CRLF) $NowCalcDate = _NowCalcDate() & " " & _NowTime(5) FileWriteLine($IE_generate_IEobjects_fileID, @CRLF & @CRLF & "; ++ Ended on " & _ $NowCalcDate & " ++++++++++++++++++++++++++") FileClose($IE_generate_IEobjects_fileID) Sleep(80) $PID = Run("notepad " & $IE_generated_script, "", @SW_HIDE) Sleep(80) $handle = WinWait("[CLASS:Notepad]", "") If $handle = 1 Then $handle = WinGetHandle("[CLASS:Notepad]", "") ; For Winwait(), 'handle = 1 when successful', ; is old functionality for AutIT3 v3.3.12.1, ; change #764 is implemented: Return Pid on ProcessWait() and handle ; on WinWait(), WinWaitActive, WinActivate(), WinActive(), WinMove() ; when successful. WinSetTrans($handle, "", $Transparancy) ; WinSetState($handle, "", @SW_RESTORE) WinSetState($handle, "", @SW_SHOW) EndFunc ;==>IE_Ending_generate ; +++++++++++++++++++++++++++++++++++++++++++++ a_Forms ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Func IE_and_Frames_generate_a_Forms_script() $x_oForms = _IEFormGetCollection($IE_oBrowser) $x_iNumForms = @extended IE_and_Frames_generate_a_Forms_script_txt($IE_oBrowser, -1) $x_oFrames = _IEFrameGetCollection($IE_oBrowser, -1) $x_iNumFrames = @extended For $iFrame = 0 To $x_iNumFrames - 1 $x_oFrame = _IEFrameGetCollection($IE_oBrowser, $iFrame) $x_oForms = _IEFormGetCollection($x_oFrame) $x_iNumForms = @extended If $x_iNumForms > 0 Then IE_and_Frames_generate_a_Forms_script_txt($x_oFrame, $iFrame) EndIf Next EndFunc ;==>IE_and_Frames_generate_a_Forms_script Func IE_and_Frames_generate_a_Forms_script_txt(ByRef $o_object, $iFrameLocal) ; $o_object is an object variable of an InternetExplorer.Application, Window, Frame or iFrame object Local $ArrayForm[1000][6], $iForm Local $i, $NameIndexnr, $TussenArr Local $id, $name, $etype For $iForm = 0 To $x_iNumForms - 1 $x_oForm = _IEFormGetCollection($o_object, $iForm) $x_oFormObjects = _IEFormElementGetCollection($x_oForm, -1) $x_iNumFormObjects = @extended For $iFormObject = 0 To $x_iNumFormObjects - 1 $x_oFormObject = _IEFormElementGetCollection($x_oForm, $iFormObject) $ArrayForm[$iFormObject][0] = $iFormObject $ArrayForm[$iFormObject][1] = $x_oFormObject.Name & ", " & StringRight("0000" & $iFormObject, 4) ; for sorting $ArrayForm[$iFormObject][2] = $x_oFormObject.Id $ArrayForm[$iFormObject][3] = $x_oFormObject.Name $ArrayForm[$iFormObject][4] = $x_oFormObject.type ; if $x_oFormObject.type = "radio" Then $ArrayForm[$iFormObject][5] = "" ; $x_oFormObject Next ; Object ; For multiple occurences of form element 'Name': add the indexnr of the name after the string 'Name#' _ArraySort($ArrayForm, 0, 0, $x_iNumFormObjects - 1, 1) ; Sort on 'Name', '$iFormObject' $NameIndexnr = 0 $i = 0 While $i < $x_iNumFormObjects - 1 $i = $i + 1 If $ArrayForm[$i][3] And $ArrayForm[$i - 1][3] Then ; No empty string $TussenArr = StringSplit($ArrayForm[$i - 1][3], "#") ; $ArrayForm[$i - 1][3] contains the # If $ArrayForm[$i][3] = $TussenArr[1] Then ; $x_oFormObject.Name ; MsgBox(4096, $ArrayForm[$i - 1][3], $ArrayForm[$i][3]) If $NameIndexnr = 0 Then $ArrayForm[$i - 1][3] = $ArrayForm[$i - 1][3] & "#0" EndIf $NameIndexnr = $NameIndexnr + 1 $ArrayForm[$i][3] = $ArrayForm[$i][3] & "#" & $NameIndexnr Else $NameIndexnr = 0 EndIf EndIf ; No empty string WEnd _ArraySort($ArrayForm, 0, 0, $x_iNumFormObjects - 1, 0) ; sort back on '$iFormObject', that is, ; in the order they were found in the Formelement collection. For $iFormObject = 0 To $x_iNumFormObjects - 1 $id = $ArrayForm[$iFormObject][2] $name = $ArrayForm[$iFormObject][3] ; $iFrameLocal ; $iForm ; $id ; $name ; $iFormObject $etype = $ArrayForm[$iFormObject][4] If $etype <> "hidden" Then ; MsgBox(4096, "", "$iFrameLocal='" & $iFrameLocal & "', $iForm='" & $iForm & "', $id='" & $id & "', _ ; $name='" & $name & "', $iFormObject='" & $iFormObject & "', $etype='" & $etype & "'") ; DOM elements can have Name or ID attributes or both. If $etype = "text" Then $FileLineCount = $FileLineCount + 2 If IsString($id) And $id <> "" Then FileWriteLine($IE_generate_IEobjects_fileID, ' _id_value_set(' & $iFrameLocal & ', ' & $iForm & _ ', "' & $id & '", ' & $iFormObject & ', ' & [email=""]'@ScriptLineNumber[/email], "", 3)' & @CRLF & @CRLF) Call("_id_value_set", $iFrameLocal, $iForm, $id, $iFormObject, $FileLineCount, "", 3) ElseIf IsString($name) And $name <> "" Then FileWriteLine($IE_generate_IEobjects_fileID, ' _name_value_set(' & $iFrameLocal & ', ' & $iForm & _ ', "' & $name & '", ' & $iFormObject & ', ' & [email=""]'@ScriptLineNumber[/email], "", 3)' & @CRLF & @CRLF) Call("_name_value_set", $iFrameLocal, $iForm, $name, $iFormObject, $FileLineCount, "", 3) Else FileWriteLine($IE_generate_IEobjects_fileID, ' _nina_value_set(' & $iFrameLocal & ', ' & $iForm & _ ', ' & $iFormObject & ', ' & $iFormObject & ', ' & [email=""]'@ScriptLineNumber[/email], "", 3)' & @CRLF & @CRLF) Call("_nina_value_set", $iFrameLocal, $iForm, $iFormObject, $iFormObject, $FileLineCount, "", 3) EndIf EndIf EndIf Next ; $iFormObject Next ; $iForm EndFunc ;==>IE_and_Frames_generate_a_Forms_script_txt ; #FUNCTION# ==================================================================================================================== ; Name...........: T_Get_oShortRef ; Description ...: This function is used to get a reference to the Internet Explorer browser or a frame or form on that browser, ; and can be called from inside as well as outside the WithPs() loop. ; Calling from within the WithPs() loop is the preferred call, because of the automatic error recovery ; (asking for new C_p* parameters). ; From outside the WithPs() loop, you have to write your won code to check if the return value is an object, ; for instance: ; $IE_oBrowser = C_Get_oShortRef(0, 1) ; If Not IsObj($IE_oBrowser) Then ... ; Syntax.........: - ; Parameters ....: - ; Return values .: On success: referenced Object ; On failure: "" ; Author ........: Martin van Leeuwen ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: no ; =============================================================================================================================== Func T_Get_oShortRef($L1, $L2) ; $oShortRef is set to IE browser, Frame or Form object Local $errorkeep, $extendedkeep ; prevent that @error and @extended will be overwritten by TuTr () Local $additional_info If StringStripWS($L1, 8) = "-1" Then $L1 = -1 If Not IsNumber($L1) Then MsgBox(4096, "1. T_Get_oShortRef", "Linenr: " & $keep_ScriptLineNumber & ", $L1=" & $L1 & ", " _ & "is however not a valid number.") Return 0 EndIf $L1 = Number($L1) If StringStripWS($L2, 8) = "-1" Then $L2 = -1 If Not IsNumber($L2) Then MsgBox(4096, "2. T_Get_oShortRef", "Linenr: " & $keep_ScriptLineNumber & ", $L2=" & $L2 & ", " _ & "is however not a valid number.") Return 0 EndIf $L2 = Number($L2) If ($L1 < -1) Then MsgBox(4096, "3. T_Get_oShortRef", "Linenr: " & $keep_ScriptLineNumber & ", $L1=" & $L1 & ", " & _ "must be" & " >= -1): ") Return 0 EndIf If ($L2 < -1) Then MsgBox(4096, "4. T_Get_oShortRef", "Linenr: " & $keep_ScriptLineNumber & ", $L2=" & $L2 & ", " & _ "must be" & " >= -1): ") Return 0 EndIf If $L1 = -1 Then $x_oFrame = $IE_oBrowser Else $x_oFrames = _IEFrameGetCollection($IE_oBrowser, -1) ; to test, if the framenr exists $errorkeep = @error ; prevent that @error and @extended will be overwritten by TuTr () $extendedkeep = @extended If $errorkeep <> 0 Then MsgBox(4096, "5. T_Get_oShortRef", "Linenr: " & $keep_ScriptLineNumber & _ ", Error in $x_oFrames = _IEFrameGetCollection($IE_oBrowser, -1)" & _ @CRLF & ", $L1: " & $L1 & ", error: " & $errorkeep & ", extended: " & $extendedkeep) Return 0 EndIf If ($L1 + 1 > $extendedkeep) Then MsgBox(4096, "6. T_Get_oShortRef", "Linenr: " & $keep_ScriptLineNumber & ", Frame nr: " & $L1 & " " & _ "is not in the range" & " 0 - " & $extendedkeep - 1) Return 0 EndIf $x_oFrame = _IEFrameGetCollection($IE_oBrowser, $L1) $errorkeep = @error ; prevent that @error and @extended will be overwritten by TuTr () $extendedkeep = @extended If $errorkeep <> 0 Then MsgBox(4096, "7. T_Get_oShortRef", "Linenr: " & $keep_ScriptLineNumber & ", Error in Frame nr: " & _ $L1 & @CRLF & $L1 & ", error: " & $errorkeep & ", extended: " & $extendedkeep) Return 0 EndIf EndIf If $L2 = -1 Then ; **** Good situation **** Return $x_oFrame Else $x_oForms = _IEFormGetCollection($x_oFrame, -1) $errorkeep = @error $extendedkeep = @extended If $errorkeep <> 0 Then $additional_info = "" If $errorkeep = 3 Then $additional_info = " (3= Invalid Data Type, can occur when the browser object is lost)" MsgBox(4096, "8. T_Get_oShortRef", "Linenr: " & $keep_ScriptLineNumber & _ ", Error in $x_oForms = _IEFormGetCollection($x_oFrame, -1)" & _ @CRLF & ", FormNr: " & $L2 & ", error: " & $errorkeep & $additional_info & ", extended: " & $extendedkeep) Return 0 EndIf If ($L2 + 1 > $extendedkeep) Then MsgBox(4096, "9. T_Get_oShortRef", "Linenr: " & $keep_ScriptLineNumber & ", Form nr: " & $L2 & " " & _ "is not in the range" & " 0 - " & $extendedkeep - 1) Return 0 EndIf $x_oForm = _IEFormGetCollection($x_oFrame, $L2) $errorkeep = @error $extendedkeep = @extended If $errorkeep <> 0 Then MsgBox(4096, "10. T_Get_oShortRef", "Linenr: " & $keep_ScriptLineNumber & ", Form nr. " & $L2 & " " & _ "is not correct, @error = " & $errorkeep & ", @extended = " & $extendedkeep) Return 0 EndIf ; **** Get Form **** Return $x_oForm EndIf EndFunc ;==>T_Get_oShortRef ; #FUNCTION# ==================================================================================================================== ; Name...........: _id_value_set ; Description ...: Use the Id of the Webpage-Control, to set the Control's value. ; Syntax.........: .. ; Parameters ....: $t1: Frame index nr. -1 = IE-browser. The counting of Framenrs starts at 0. ; $t2: Form index nr. -1 = No Form. The counting of Formnrs starts at 0. ; $t3: Id of the form - element. See_IEGetObjById - Specifies id of the object you wish ; to match $o_object.document.getElementById($s_Id) ; $t4: New value ; $IE_function: "" is for using the default value. ; An optional additional string "*Tuned*YYYYMMDD" is for Tuned functions. ; $FireEvent_Plus2 FireEvent, 2 = False, 3 = True (Default) ; Return values .: not applicable ; Author ........: Martin van Leeuwen ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _id_value_set($Frame_index, $Form_index, $id, $Value, $ScriptLineNumber, $IE_function, $FireEvent_Plus2) $keep_ScriptLineNumber = $ScriptLineNumber $IE_oBrowserFrameForm = T_Get_oShortRef($Frame_index, $Form_index) ; when searched and found by ; '_IEFormElementGetCollection($Form_index, $object_index)', ; then $t2(Form index) has the value 0 or > 0 If Not IsObj($IE_oBrowserFrameForm) Then Return $IE_oObj = _IEFormElementGetObjByName($IE_oBrowserFrameForm, $id) If @error <> 0 Then MsgBox(4096, "_id_value_set", "Linenr: " & $keep_ScriptLineNumber & ", _IEFormElementGetObjByName" & ", $id=" & $id & _ ", @error=" & @error & ", [email="_@extended"]_@extended[/email]=" & @extended) Return EndIf $C_out = _IEFormElementSetValue($IE_oObj, $Value, $FireEvent_Plus2 - 2) ; $FireEvent_Plus2 = 3 If @error <> 0 Then MsgBox(4096, "_id_value_set", "Linenr: " & $keep_ScriptLineNumber & ", _IEFormElementSetValue" & ", $Value=" & _ $Value & ", @error=" & @error & ", @extended=" & @extended) Return EndIf EndFunc ;==>_id_value_set ; #FUNCTION# ==================================================================================================================== ; Name...........: _name_value_set ; Description ...: Use the name of the Webpage-Control, to set the Control's value. ; Syntax.........: .. ; Parameters ....: $t1: Frame index nr. -1 = IE-browser. The counting of Framenrs starts at 0. ; $t2: Form index nr. -1 = No Form. The counting of Formnrs starts at 0. ; $t3: Id of the form - element, _IEGetObjByName - Specifies name or id of the object you ; wish to match. $o_object.document.GetElementsByName($s_Id).item($i_index) ; Martin: an id has has index = 0, a name can occur once or more, having $i_index = 0 or > 0 ; $t4: New value ; FireEvent_Plus2 Default value of $FireEvent_Plus2 = 3 -> $FireEvent = 1 ; $IE_function: "" is for using the default value. ; An optional additional string "*Tuned*YYYYMMDD" is for Tuned functions. ; $FireEvent_Plus2 FireEvent, 2 = False, 3 = True (Default) ; Return values .: not applicable ; Author ........: Martin van Leeuwen ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _name_value_set($Frame_index, $Form_index, $Object_name, $Value, $ScriptLineNumber, $IE_function, $FireEvent_Plus2) Local $name_arr $keep_ScriptLineNumber = $ScriptLineNumber $IE_oBrowserFrameForm = T_Get_oShortRef($Frame_index, $Form_index) ; when searched and found by ; '_IEFormElementGetCollection($Form_index, $object_index)', ; then $t2(Form index) has the value 0 or > 0 If Not IsObj($IE_oBrowserFrameForm) Then Return $name_arr = StringSplit($Object_name, "#") If $name_arr[0] = 1 Then $name_arr = StringSplit($Object_name & "#0", "#") EndIf If $name_arr[0] <> 2 Then MsgBox(4096, "_name_value_set", "Linenr: " & $keep_ScriptLineNumber & _ ', Format for p3 is "name#index", but # is found more than once.') Return EndIf $IE_oObj = _IEFormElementGetObjByName($IE_oBrowserFrameForm, $name_arr[1], $name_arr[2]) If @error <> 0 Then MsgBox(4096, "_name_value_set", "Linenr: " & $keep_ScriptLineNumber & _ ', _IEFormElementGetObjByName, $name_arr[1]="' & $name_arr[1] & _ '", $name_arr[2]=' & $name_arr[2] & ", @error=" & @error & ", @extended=" & @extended) Return EndIf $C_out = _IEFormElementSetValue($IE_oObj, $Value, $FireEvent_Plus2 - 2) ; $FireEvent_Plus2 = 3 If @error <> 0 Then MsgBox(4096, "_name_value_set", "Linenr: " & $keep_ScriptLineNumber & _ ', _IEFormElementSetValue, $name_arr[1]="' & $name_arr[1] & _ '", $name_arr[2]=' & $name_arr[2] & ", $Value=" & $Value & ", @error=" & @error & ", @extended=" & @extended) Return EndIf EndFunc ;==>_name_value_set ; #FUNCTION# ==================================================================================================================== ; Name...........: _nina_value_set ; Description ...: ( nina = No Id and No Name ) ; Use the index nr of the Webpage-Control without an Id or Name, to set the value of the Control. ; Parameters ....: $t1: Frame index nr. -1 = IE-browser. The counting of Framenrs starts at 0. ; $t2: Form index nr. -1 = No Form. The counting of Formnrs starts at 0. ; $t3: Use the index of the object, starting with 0. ; In use when the object has No ID and No Name on this IE browser or Frame. ; The AutoIT function that is used, counting from index = 0, is: ; _IEFormElementGetCollection($t_oForm, $iFormObjectIndex) ; $IE_function: "" is for using the default value. An optional additional string "*Tuned*YYYYMMDD" ; is for Tuned functions. ; $FireEvent_Plus2 FireEvent, 2 = False, 3 = True (Default) ; Return values .: not applicable ; Author ........: Martin van Leeuwen ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _nina_value_set($Frame_index, $Form_index, $Object_index, $Value, $ScriptLineNumber, $IE_function, $FireEvent_Plus2) $keep_ScriptLineNumber = $ScriptLineNumber $IE_oBrowserFrameForm = T_Get_oShortRef($Frame_index, $Form_index) ; $Form_index has the value 0 or > 0, ; when the object is searched and found using '_IEFormElementGetCollection($Form_index, $Object_index)' If Not IsObj($IE_oBrowserFrameForm) Then Return $IE_oObj = _IEFormElementGetCollection($IE_oBrowserFrameForm, $Object_index) If @error <> 0 Then MsgBox(4096, "_nina_value_set", "Linenr: " & $keep_ScriptLineNumber & ", _IEFormElementGetCollection" & _ ", $Object_index=" & $Object_index & ", @error=" & @error & ", @extended=" & @extended) Return EndIf $C_out = _IEFormElementSetValue($IE_oObj, $Value, $FireEvent_Plus2 - 2) ; $FireEvent_Plus2 = 3 If @error <> 0 Then MsgBox(4096, "_nina_value_set", "Linenr: " & $keep_ScriptLineNumber & ", _IEFormElementSetValue" & ", $Value=" & _ $Value & ", @error=" & @error & ", @extended=" & @extended) Return EndIf EndFunc ;==>_nina_value_set ;
-
[/right] [right]; ok?[/right] [right]
-
I use SciTE and the Tidy hotkey <Ctrl>T to format the code ...