Jump to content

Recommended Posts

Posted

Hi,

additional to the 'Show IE Object' script that I posted last week, I have a new script for you:

wiIt generates script lines for the Internet Explorer Form elements, type is 'text', I tested it in IE8 with the new beta v3.3.7.21

; ===============================================================================================================================

; Title .........: AC generate IE script v0.1.au3

; Version : 0.1.11

; Date : 29 november 2011

; Language ......: English en Nederlands

; Description ...: Generate the AutoIT script for Internet Explorer Webpage-Controls.

; 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) ; "Terneuzen"

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 & ', ' & '@ScriptLineNumber, "", 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 & ', ' & '@ScriptLineNumber, "", 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 & ', ' & '@ScriptLineNumber, "", 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 & ", @extended=" & @extended)

Return

EndIf

$C_out = _IEFormElementSetValue($IE_oObj, $Value, $FireEvent_Plus2 - 2) ; $C_p4 = $s_newvalue $f_fireEvent = 1

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) ; $C_p4 = $s_newvalue $f_fireEvent = 1

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) ; $C_p4 = $s_newvalue $f_fireEvent = 1

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

Posted

Could you please put AutoIt code tags around your code? So it gets nicely formated and is much much more readable.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • Moderators
Posted

MvL,

What water means is to put "autoit tags" before and after the code in the first post. If you put [autoit] before and [/autoit] after your posted code it appears in a nice scrolling box and with coloured formatting like this: :D

; Hi I am between autoit tags
$sVariable = "Fred"

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

It's not just the AutoIt tags that are not ok ! :D

C:Documents and SettingsAdministrateurLocal SettingsTempTest_0373.au3(236,141) : ERROR: syntax error

FileWriteLine($IE_generate_IEobjects_fileID, ' _id_value_set(' & $iFrameLocal & ', ' & $iForm & ', "' & $id & '", ' & $iFormObject & ', ' & [

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:Documents and SettingsAdministrateurLocal SettingsTempTest_0373.au3(239,145) : ERROR: syntax error

FileWriteLine($IE_generate_IEobjects_fileID, ' _name_value_set(' & $iFrameLocal & ', ' & $iForm & ', "' & $name & '", ' & $iFormObject & ', ' & [

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:Documents and SettingsAdministrateurLocal SettingsTempTest_0373.au3(242,150) : ERROR: syntax error

FileWriteLine($IE_generate_IEobjects_fileID, ' _nina_value_set(' & $iFrameLocal & ', ' & $iForm & ', ' & $iFormObject & ', ' & $iFormObject & ', ' & [

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:Documents and SettingsAdministrateurLocal SettingsTempTest_0373.au3(464,6) : ERROR: syntax error

Like This

~~~~~^

C:Documents and SettingsAdministrateurLocal SettingsTempTest_0373.au3 - 4 error(s), 0 warning(s)

!>21:41:58 AU3Check ended.rc:2

>Exit code: 0 Time: 0.420

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts

Posted

;
; ===============================================================================================================================
; 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

;

Posted

Much better :D

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Posted

Much better :oops:

? :D

C:Documents and SettingsAdministrateurLocal SettingsTempTest_0374.au3(246,53) : ERROR: syntax error

', "' & $id & '", ' & $iFormObject & ', ' & [

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:Documents and SettingsAdministrateurLocal SettingsTempTest_0374.au3(250,55) : ERROR: syntax error

', "' & $name & '", ' & $iFormObject & ', ' & [

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:Documents and SettingsAdministrateurLocal SettingsTempTest_0374.au3(254,60) : ERROR: syntax error

', ' & $iFormObject & ', ' & $iFormObject & ', ' & [

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:Documents and SettingsAdministrateurLocal SettingsTempTest_0374.au3(403,39) : ERROR: syntax error

", @error=" & @error & ", [email="_

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:Documents and SettingsAdministrateurLocal SettingsTempTest_0374.au3 - 4 error(s), 0 warning(s)

AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts

Posted

? :D

Didn't check the syntax just the usage of the autoit tags

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...