Good stuff, Jeff, thanks for putting that up there for everyone to latch
on to.
JW
Jeff Bishop wrote:
Hello Scripters and specifically Jamal,
Jamal, due to the way your logic is written in:
Function HandleStateChange(sObject, bLoaded)
you need to insure that you do not Queue the call to check for
update. You need to insure it completes before you hit the code below.
For those interested, here is how I troubleshooted the issue:
1. I first added a bunch of lines that looked like the following:
Dim boolFlag
boolFlag = False
If oHomer Is Nothing Then
Speak "Homer not found"
boolFlag = True
Else
Speak "Homer found"
End If
If oHotkeyManager Is Nothing Then
Speak "hotkey manager not found"
boolFlag = True
Else
Speak "hotkey manager found"
End If
If oHelpDialog Is Nothing Then
Speak "Help dialog not found"
boolFlag = True
Else
Speak "Help dialog found"
End If
If oCheckForUpdate Is Nothing Then
Speak "check for update not found"
boolFlag = True
Else
Speak "Check for Update found"
End If
If oErrorReporting Is Nothing Then
Speak "error reporting not found"
boolFlag = True
Else
Speak "Error Reporting Found"
End If
If boolFlag Then
SetData "ScriptInitialized", False
Else
If iHandleHotkey = 0 Then ConnectEvent Application, "OnHotkey",
"HandleHotkey"
If iHandleActivate = 0 Then ConnectEvent DesktopWindow,
"OnChildActivate", "HandleActivate"
RegisterHotkeys
SetData "ScriptInitialized", True
End If
End Function
The code originally looked like this:
If oHomer Is Nothing Or oHotkeyManager Is Nothing Or oHelpDialog Is
Nothing Or oCheckForUpdate Is Nothing Or oErrorReporting Is Nothing Then
SetData "ScriptInitialized", False
Else
If iHandleHotkey = 0 Then ConnectEvent Application, "OnHotkey",
"HandleHotkey"
If iHandleActivate = 0 Then ConnectEvent DesktopWindow,
"OnChildActivate", "HandleActivate"
RegisterHotkeys
SetData "ScriptInitialized", True
End If
End Function
I did this to pin point which shared object was failing.
2. I then examined the SetCheckForUpdate procedure and found a bug.
I changed it to this:
If oScriptINI.Number("Automatic_Updates", "OnScriptStart", 0) = 1 Then
oCheckForUpdate.CheckForUpdate
In addition, I added a speak statement to it at the top. So, it read:
Speak "Checking for update"
Set oCheckForUpdate =
SharedObjects("com.GWMicro.GWToolkit.CheckForUpdate").NewCheck
With oCheckForUpdate
.ScriptVersion = oData("ScriptVersion")
.UpdateUrl = oData("ScriptUpdateURL")
End With
If oScriptINI.Number("Automatic_Updates", "OnScriptStart", 0) = 1
Then oCheckForUpdate.CheckForUpdate
3. I then ran the code and noticed that CheckForUpdate was not being
seen or, well, it was but the issues still persisted where keys were
not being initialized.
4. I then went to the on state change function and did this:
Case "com.GWMicro.GWToolkit.CheckForUpdate"
If bLoaded Then
Call SetCheckForUpdate
Else
Set oCheckForUpdate = Nothing
End If
I had to change the SetCheckForUpdate to a sub from a function as
well, so it read:
Sub SetCheckForUpdate()
' Set CheckForUpdate object, and check if auto setting
Speak "Checking for update"
Set oCheckForUpdate =
SharedObjects("com.GWMicro.GWToolkit.CheckForUpdate").NewCheck
With oCheckForUpdate
.ScriptVersion = oData("ScriptVersion")
.UpdateUrl = oData("ScriptUpdateURL")
End With
If oScriptINI.Number("Automatic_Updates", "OnScriptStart", 0) = 1
Then oCheckForUpdate.CheckForUpdate
End Sub
I then ran the script, and guess what, it worked.
So, there you go, everyone should be happy <grin>.