Sederien Posted May 7, 2006 Share Posted May 7, 2006 (edited) I'm not really a BASIC programmer in any sense, since today is really my first time using it (or anything similiar) at all. As such, what I'm trying to achieve is pretty basic (pun intended), but I'm not quite sure how to get it right. We're starting in an IE window with the IE.au3 function library already called. The page may have a loginform object, and it may not. If it has one, I'd like to process XCOMMAND. If not, do nothing and continue with the rest of the script. Here's what I tried: $o_form = _IEFormGetObjByName($oIE, "loginform") If NOT $o_form = "0" Then XCOMMAND EndIf However, this doesn't seem to work as intended. Here's the _IEFormGetObjByName function: ;=============================================================================== ; ; Function Name: _IEFormGetObjByName() ; Description: Returns an object reference to a Form by name ; Parameter(s): $o_object - Object variable of an InternetExplorer.Application, Window or Frame object ; $s_name - Name of the Form you wish to match ; $i_index - Optional: If the Form name occurs more than once, specify which instance ; you want by 0-based index ; Note: $i_index can also be set to -1 to return a collection object ; Requirement(s): AutoIt3 Beta with COM support (post 3.1.1) ; Return Value(s): On Success - Returns an object variable pointing to the Form object, @EXTENDED = form count ; On Failure - Returns 0 and sets @ERROR = 1 ; Author(s): Dale Hohm ; ;=============================================================================== ; Func _IEFormGetObjByName($o_object, $s_Name, $i_index = 0) If Not IsObj($o_object) Then SetError(1) Return 0 EndIf ; If $i_index = -1 Then SetError(0) SetExtended($o_object.document.forms.length) Return $o_object.document.forms.item ($s_Name) Else SetError(0) SetExtended($o_object.document.forms.length) Return $o_object.document.forms.item ($s_Name, $i_index) EndIf EndFunc ;==>_IEFormGetObjByName Any suggestions to a BASIC newb? I think I'm either using "If NOT" completely wrong (Hey! I'm a PHP/HTML guy... Never worked with base languages before), or I'm using the wrong value for trying to assess if $o_form came back negative. Thanks in advance! P.S. (Latest beta AutoIt in use.) EDIT: Wrong code reference. Edited May 7, 2006 by Sederien Link to comment Share on other sites More sharing options...
Valuater Posted May 7, 2006 Share Posted May 7, 2006 it cant work $o_form = _IEFormGetObjByName($oIE, "loginform") If NOT $o_form = "0" Then XCOMMAND EndIfHowever, this doesn't seem to work as intended. Here's the _IEFormGetObjByName function:CODE;===============================================================================;; Function Name: _IEFrameGetObjByName()frame or form???8) Link to comment Share on other sites More sharing options...
Sederien Posted May 7, 2006 Author Share Posted May 7, 2006 it cant workframe or form???8)Heh... Form. Fixed it above and properly beat myself . I may be a coding newb, but I should know better how to post on a forum.Can it work now? ^^ Link to comment Share on other sites More sharing options...
Valuater Posted May 7, 2006 Share Posted May 7, 2006 (edited) the complete IE.au3 file should be placed in the beta\include folder and it DOES NEED beta to work... also make sure you have the latest IE.au3 T2 file for internet explorer this is how the script should look #include<IE.au3> $oIE = _IECreate () $o_form = _IEFormGetObjByName ($oIE, "loginform") If @error = 1 Then MsgBox(0, "sorry", "not found" , 2) ; do this Else MsgBox(0, "Yea!","found", 2) ; or do that EndIf but i get an "ok" message ... there may be a problem... per the function On Failure - Returns 0 and sets @ERROR = 1 dunno????? anyways... to learn alot quickly ... and get everything you need.... go here http://www.autoitscript.com/forum/index.php?showtopic=21048# 8) Edited May 7, 2006 by Valuater Link to comment Share on other sites More sharing options...
Sederien Posted May 7, 2006 Author Share Posted May 7, 2006 the complete IE.au3 file should be placed in the beta\include folder and it DOES NEED beta to work... also make sure you have the latest IE.au3 T2 file for internet explorer this is how the script should look [snip] but i get an "ok" message ... there may be a problem... per the function dunno????? Yep... Tried that one myself. Seems to run the Else statement always (signalling that @error is always 0 regardless of the loginform existing). anyways... to learn alot quickly ... and get everything you need.... go here http://www.autoitscript.com/forum/index.php?showtopic=21048# 8) Did that within the first half hour. Is very nice and I do thank you for it. Doesn't quite solve this problem though... Still looking into other options. Link to comment Share on other sites More sharing options...
Valuater Posted May 7, 2006 Share Posted May 7, 2006 got an idea... hold a sec... 8) Link to comment Share on other sites More sharing options...
Sederien Posted May 7, 2006 Author Share Posted May 7, 2006 got an idea... hold a sec...8)*laughing*Holding. (Again, thanks for the help either way!) Link to comment Share on other sites More sharing options...
Valuater Posted May 7, 2006 Share Posted May 7, 2006 lesson #15 from "Welcome to Autoit 1-2-3 expandcollapse popup; demonstration to find chracters that change between to standard points ; or just find a string #include <IE.au3> #Region --- IE-Builder generated code Start --- $oIE = _IECreate () ;------------- User input -------------- _IENavigate ($oIE, "http://www.autoitscript.com/"); web address $Find = "loginform"; my info shows after this line... or just find this line $Before = ""; my info shows before this line... or set as "" ; ------------ End User input ------------- Sleep(1000) $body = _IEBodyReadHTML ($oIE) $sloc = @TempDir & "\stest.txt" FileDelete($sloc) FileWrite($sloc, $body) $sfile = FileOpen($sloc, 0) $num = 0 While 2 $num = $num + 1 $sline = FileReadLine($sfile, $num) If @error Then MsgBox(262208, "Fail", "The string was NOT found ") FileClose($sfile) Exit EndIf If StringInStr($sline, $Find) Then MsgBox(64, "Success", "The string " & $Find & " was found " & @CRLF & " on line # " & $num, 5) If $Before = "" Then ExitLoop $Found = stringbetween($sline, $Find, $Before) MsgBox(64, "Found", "The string is " & $Found & " ", 5) ExitLoop EndIf WEnd Func stringbetween($str, $start, $end) $pos = StringInStr($str, $start) If Not @error Then $str = StringTrimLeft($str, $pos + StringLen($start) - 1) $pos = StringInStr($str, $end) If Not @error Then $str = StringTrimRight($str, StringLen($str) - $pos + 1) Return $str EndIf EndIf EndFunc ;==>stringbetween #EndRegion --- IE-Builder generated code End --- 8) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now