COM: Works only when I change function name

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Johana
Posts: 189
Joined: 02 May 2017, 02:34

COM: Works only when I change function name

17 Nov 2017, 07:42

I have a mysterious problem I really can't seem to understand. This is my script. I access it by either run command or by doubleclicking the script. Sometimes it works, sometimes it doesn't.

Listlines at top of the script shows it's doing everything it's supposed too. It iopen IE url but doesn't click. If I however change "wb" to "xx" where xx is anything else than wb it works. Next time if I run it (and this happens even if i restart the pc) it stops working, then I have to change xx to a new xx (xx is whatever letters I write, randomly).

Here's the code:

Code: Select all

#persistent
#Singleinstance, force
#NoEnv
Gui, LunchTime:new
Gui, LunchTime:color, green
Gui, LunchTime:-caption
Gui, LunchTime:add, edit, w50 limit2 number vLunchTid
Gui, LunchTime:add, button, Hidden default, submit
Gui, LunchTime:show, autosize, Lunch
return

LunchTimeButtonSubmit:
gui, LunchTime:submit
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := false
wb.Navigate("https://checkin.com/")
IELoad(wb)
wb.document.GetElementByID("out").click()
wb.quit
settimer, lunch_time, % 1000 * 60 * lunchtid ; Minutes
Gui, LunchTime:destroy
return

LunchTimeGuiEscape:
LunchTimeGuiClose:
Gui, LunchTime:destroy
return

lunch_time:
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := false
wb.Navigate("https://checkin.com")
IELoad(wb)
wb.document.GetElementByID("inn").click()
wb.quit
settimer, lunch_time, off
return

IELoad(wb)
{
	global
    If !wb    ;If wb is not a valid pointer then quit
        Return False
    Loop    ;Otherwise sleep for .1 seconds untill the page starts loading
        Sleep,100
    Until (wb.busy)
    Loop    ;Once it starts loading wait until completes
        Sleep,100
    Until (!wb.busy)
    Loop    ;optional check to wait for the page to completely load
        Sleep,100
    Until (wb.Document.Readystate = "Complete")
	Return True
}

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: COM: Works only when I change function name

17 Nov 2017, 09:16

Not really my cup of tea, but I'd guess that that Readystate condition (or that section at all) needs to be re-adjusted (?)
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Re: COM: Works only when I change function name

17 Nov 2017, 09:33

BoBo wrote:Not really my cup of tea, but I'd guess that that Readystate condition (or that section at all) needs to be re-adjusted (?)
Hey BoBo, not my cup of anything either. But if it's the readystate, why is it working if I just change all the "wb" to let's say "blabla"
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: COM: Works only when I change function name

17 Nov 2017, 10:21

Your IEload function is global so the wb variable inside the function is not safe
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Re: COM: Works only when I change function name

20 Nov 2017, 06:50

Blackholyman wrote:Your IEload function is global so the wb variable inside the function is not safe
Thanks! I'll try to remove it and see if it works.
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Re: COM: Works only when I change function name

22 Nov 2017, 09:53

Nope. Doesn't work :( :(
Blackholyman wrote:Your IEload function is global so the wb variable inside the function is not safe

Code: Select all

listlines
#persistent
#Singleinstance, force
#NoEnv
XwbX := ComObjCreate("InternetExplorer.Application")
XwbX.Visible := false
XwbX.Navigate("https://website.com")
IELoad(XwbX)
XwbX.document.GetElementByID("out").click()
XwbX.quit
settimer, lunch_time, % 1000 * 60 * 30 ; 30 minutes
return

lunch_time:
XwbX := ComObjCreate("InternetExplorer.Application")
XwbX.Visible := false
XwbX.Navigate("https://website.com/")
IELoad(XwbX)
XwbX.document.GetElementByID("in").click()
XwbX.quit
settimer, lunch_time, off
exitapp
return

IELoad(XwbX)
{
	If !XwbX    ;If XwbX is not a valid pointer then quit
        Return False
    Loop    ;Otherwise sleep for .1 seconds untill the page starts loading
        Sleep,100
    Until (XwbX.busy)
    Loop    ;Once it starts loading wait until completes
        Sleep,100
    Until (!XwbX.busy)
    Loop    ;optional check to wait for the page to completely load
        Sleep,100
    Until (XwbX.Document.Readystate = "Complete")
	Return True
}

Listlines:

Code: Select all

001: ListLines (0.05)
005: XwbX := ComObjCreate("InternetExplorer.Application") (0.17)
006: XwbX.Visible := false  
007: XwbX.Navigate("https://website.com/")   (0.03)
008: IELoad(XwbX)  
027: if !XwbX  
029: Loop
030: Sleep,100 (0.11)
031: Until,(XwbX.busy)
032: Loop
033: Sleep,100 (0.11)
034: Until,(!XwbX.busy)
035: Loop
036: Sleep,100 (0.11)
037: Until,(XwbX.Document.Readystate = "Complete")
038: Return,True
009: XwbX.document.GetElementByID("out").click()  
010: XwbX.quit  
011: SetTimer,lunch_time,1000 * 60 * 30
012: Return (10.33)
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: COM: Works only when I change function name

22 Nov 2017, 10:44

Well it did make the function local

For your other issue you need to give the browser time to do the click before you ask it to quit
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Re: COM: Works only when I change function name

27 Nov 2017, 09:47

Blackholyman wrote:Well it did make the function local

For your other issue you need to give the browser time to do the click before you ask it to quit
I tried with sleep, 4000. Still not working. Any other suggestions?
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Re: COM: Works only when I change function name

29 Nov 2017, 08:31

I removed quit, and so far it seems working. But is there no way to tell it "when it's fully loaded, wait a Little, then quit" ?
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: COM: Works only when I change function name

29 Nov 2017, 08:45

it depends but you can try something like this

Code: Select all

IELoad(wb)
wb.document.GetElementByID("out").click()
IELoad(wb)
wb.quit
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Haris00911, RussF, Swiftly9767 and 289 guests