Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

COM Object Reference [AutoHotkey v1.1+]


  • Please log in to reply
233 replies to this topic
mikek
  • Members
  • 161 posts
  • Last active: Nov 09 2015 05:02 PM
  • Joined: 21 Nov 2008

I would like to get more current on my usage of COM with Internet Explorer. I have studied Jethrow's code and am wondering if someone can explain the difference between two different commands with comments which indicate identical use. However, that Jethrow would use both in his example indicates that the commands do different things.

;// the ReadyState will be 4 when the page is loaded
while wb.ReadyState <> 4
    continue

This code above caused the script to wait until the page loaded before continuing.

;// the Busy property will be true while the page is loading
while wb.Busy
    continue

This code above sounds like it does the same thing. Does this have a different purpose? When I substituted this code after sending a navigate command, ahk did not fully wait for the page to load before continuing.

 

Thank you.

 

- Mike

 



jethrow
  • Moderators
  • 2854 posts
  • Last active: May 17 2017 01:57 AM
  • Joined: 24 May 2009

Note that neither ReadyState nor Busy are commands in the examples - they are both object properties. As such, you can go look at the webbrowser object properties for more info.

 

Webpage designs can be diverse - as you may have noticed if you've browsed the internet. As such, a webpage "being finished loading" doesn't mean the exact same thing for every page - just saying.

 

That said, either waiting for the webbrowser object to not be busy or waiting for it's readystate to be 4 (and then the document object readystate to be "complete")  should be sufficient for concluding the webpage is loaded. Note that you could also wait for the DocumentComplete event to be fired by the webbrowser object.

 

I typically check the busy property because it requires at least 7 less keypresses.



J_Derek
  • Members
  • 2 posts
  • Last active: May 16 2014 03:13 PM
  • Joined: 09 May 2014

Im trying to convert some VBScript into AHK_L but I don't know the proper syntax. I hope someone can help out.

 

Here is the VBScript code:

Const adLongVarBinary = 205
RS = CreateObject("ADODB.Recordset")
RS.Fields.Append "b", adLongVarBinary, Len(Pre) + LenB(FileContents) + Len(Po)
  RS.Open
  RS.AddNew
    Dim LenData
    'Convert Pre string value To a binary data
    LenData = Len(Pre)
    RS("b").AppendChunk (StringToMB(Pre) & ChrB(0))
    Pre = RS("b").GetChunk(LenData)
    RS("b") = ""
    
    'Convert Po string value To a binary data
    LenData = Len(Po)
    RS("b").AppendChunk (StringToMB(Po) & ChrB(0))
    Po = RS("b").GetChunk(LenData)
    RS("b") = ""
    
    'Join Pre + FileContents + Po binary data
    RS("b").AppendChunk (Pre)
    RS("b").AppendChunk (FileContents)
    RS("b").AppendChunk (Po)
  RS.Update
  FormData = RS("b")
  RS.Close

And this is what I have so far for the AutoHotKey code:

adLongVarBinary = 205
RS := ComObjCreate("ADODB.Recordset")
RS.fields.Append("b", adLongVarBinary, len)
RS.open()
RS.AddNew()

; -- Convert Pre string value to a binary data
RS.("b").AppendChunk(preToMB)
Pre := RS.("b").GetChunk(lenPre)
RS.fields("b") := 

My problem is that I dont know the syntax for converting RS.("b") into autohotkey.

 

 



A117
  • Members
  • 14 posts
  • Last active: Jan 20 2015 01:26 AM
  • Joined: 14 Jun 2012
My script nearly always knock into a timing out error by AHK at WebRequest.send().
Can this error be caught please?
&nbsp;

More importantly, what can Scripting.Dictionary do that the built-in objects can't do?

COM Object: WinHttpRequest
Purpose: Provides simple HTTP client functionality, allowing much more control than UrlDownloadToFile.
System Requirements: General*
Documentation Link: &lt;!-- m --&gt;http://msdn.microsof...y/aa384106.aspx&lt;!-- m --&gt;
Basic Code Example:

WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")WebRequest.Open("GET", "http://www.autohotkey.net/~Lexikos/AutoHotkey_L/docs/AHKL_ChangeLog.htm")WebRequest.Send()RegExMatch(WebRequest.ResponseText, "(?&lt;=&lt;h2&gt;).*?(?=&lt;/h2&gt;)", ver)MsgBox % verWebRequest := "" 
* Note MSDN says Windows 2000 or later required, but I've seen some other cases where this wasn't accurate; maybe they say that since they really don't support older versions of Windows. Furthermore, AutoHotkey_L requires Windows 2000 or later.

Btw, perhaps the wiki is a good place to put this reference (without the discussion).
&nbsp;

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

You can try to catch it... ;)



smorgasboard
  • Members
  • 660 posts
  • Last active: Jan 14 2016 08:53 AM
  • Joined: 18 Jul 2012

 

COM Object: Word.Application
Purpose: create and edit various documents
System Requirements: Microsoft Office Word application
Documentation Link: <!-- m -->http://msdn.microsof...ry ... 12).aspx<!-- m -->
Other Links:
Basic Code Example:


oWord := ComObjCreate("Word.Application") ; create MS Word object
oWord.Documents.Add ; create new document

oWord.Selection.Font.Bold := 1 ; bold
oWord.Selection.TypeText("Visit ") ; type text
oWord.ActiveDocument.Hyperlinks.Add(oWord.Selection.Range, "http://www.autohotkey.com/forum/topic61509.html"
,"","","COM Object Reference [AutoHotkey_L]") ; insert hyperlink
oWord.Selection.TypeText("and learn how to work with ") ; type text
oWord.Selection.Font.Italic := 1 ; italic
oWord.Selection.TypeText("COM objects") ; type text
oWord.Selection.Font.Bold := 0, oWord.Selection.Font.Italic := 0 ; bold and italic off
oWord.Selection.TypeText(".") ; type text
oWord.Selection.TypeParagraph ; type paragraph (enter, new line)

oWord.Visible := 1, oWord.Activate ; make it visible and activate it.
ExitApp

registered.

thanks to Learning One and evilC



bleonard252
  • Members
  • 3 posts
  • Last active: Apr 08 2015 02:10 AM
  • Joined: 07 Apr 2015

Agreed
:D - who hasn't wanted to b**ch slap tank at one point or another? :p

Me. I haven't. If you want a browser control, position a GroupBox in SmartGUI editor or something and edit the script in SciTE after :p

Then edit it and carefully replace it with the code from the AutoHotkey help file (hint, it's in the ActiveX control area)

The page never popped up, but it could be because IE is SLOOOOW and hated by all. Literally.

 

 

~Moderator: Necropost Alert!



bleonard252
  • Members
  • 3 posts
  • Last active: Apr 08 2015 02:10 AM
  • Joined: 07 Apr 2015

My script nearly always knock into a timing out error by AHK at WebRequest.send().

Mine did that once too. You have to have Internet access, and the latest IE. And it has to be put in right wink.png
So yeah, there you have it.

No catching needed ;) Just solve the error and GET A GOOD INTERNET!



matjo
  • New members
  • 1 posts
  • Last active: Jul 17 2015 01:04 PM
  • Joined: 16 Jul 2015

QUESTION(by newbie): COM: sending input to HTML FORM does not work when using local HTML FORM.

 

- aim is to send data/populate HTML FORM from AHK.

- HTML file with FORM is saved locally, and contains some javascript to process input data.

- the same code works when using online html form ie using first url from code example.

- is it possible to send data with ahk to HTML FORM that is saved on local drive? 

; not working - WHEN OPENED FROM LOCAL FILE
; INPUT VALUES INTO HTML FORM
; CF SAME FORM WORKS WHEN OPENED FROM WWW!!!!!!!!!!!!!!!!!!!

; FORM url from www WORKS
;url = http://www.html5rocks.com/en/tutorials/forms/html5forms/input-types.html
; FORM url form local drive - DOES NOT WORK
; to test - download http://www.html5rocks.com/en/tutorials/forms/html5forms/input-types.html to working directory (%A_ScriptDir%)
url = %A_ScriptDir%/input-types.html

wb := ComObjCreate("InternetExplorer.Application") ; 
wb.Visible := true
wb.Navigate(url)
While wb.ReadyState != 4 || wb.document.ReadyState != "complete" || wb.busy ; wait for the page to load
	Sleep, 3010

	wb.document.all.email_addr.value  := "AHK_NEW_ADDRESS_FROM"  
	wb.document.all.first_last.value  := "AHK_LAST_NAME"  

	sleep 2000
msgbox 
wb.quit()

error is 

Error:  0x800706B5 - Neznáme rozhranie.
Specifically: ReadyState
	Line#
	003: SendMode,Input
	004: SetWorkingDir,%A_ScriptDir%
	013: url = %A_ScriptDir%/htmlform.html
	015: wb := ComObjCreate("InternetExplorer.Application")
	016: wb.Visible := true  
	017: wb.Navigate(url)  
--->	018: While,wb.ReadyState != 4 || wb.document.ReadyState != "complete" || wb.busy
	019: Sleep,3010
	021: wb.document.all.email_addr.value  := "AHK_NEW_ADDRESS_FROM"  
	022: wb.document.all.first_last.value  := "AHK_LAST_NAME"  
	024: Sleep,2000
	025: MsgBox
	026: wb.quit()  
	027: Exit
Continue running the script? 

when I delete line 018, error reads: 

Error:  0x800706B5 - Neznáme rozhranie.
Specifically: document
	Line#
	003: SendMode,Input
	004: SetWorkingDir,%A_ScriptDir%
	013: url = %A_ScriptDir%/htmlform.html
	015: wb := ComObjCreate("InternetExplorer.Application")
	016: wb.Visible := true  
	017: wb.Navigate(url)  
	019: Sleep,3010
--->	021: wb.document.all.email_addr.value  := "AHK_NEW_ADDRESS_FROM"  
	022: wb.document.all.first_last.value  := "AHK_LAST_NAME"  
	024: Sleep,2000
	025: MsgBox
	026: wb.quit()  
	027: Exit
	028: Exit
	028: Exit

Continue running the script?
 

 thanks for info if it is doable or not, and for any insight, 

 

matjo