Trouble with State Change

Hi. I've got some experience with VBScipt but I' realatively new to scipting for DesktopX so bear with me, here.

I'm trying to set up script code which will bring an object to the to of the Z-order upon pressing a hot key. Here's my code:

---------
'Called when the script is executed
Sub Object_OnScriptEnter
Set form=Desktopx.CreateForm
form.AddPreference("Hotkey")
form.Preference("Hotkey").Type="hotkey"
form.Preference("Hotkey").Caption="Hotkey:"
form.Preference("Hotkey").Value=h
If( form.Prompt ) Then
h=form.Preference("Hotkey").Value
MsgBox("Setting hotkey")
Object.RegisterHotkey 1, form.Preference("Hotkey").Value
End If
End Sub

'Called when the script is terminated
Sub Object_OnScriptExit
Object.UnregisterHotkey 1
End Sub

Sub Object_OnHotkey(id)
Object.State = Riseup
End Sub

Sub Object_OnStateChange(Riseup)
Object.OnTop
msgbox("Hit")
End Sub
------

The hot key works and I do get a message box which dispalys the word "Hit". But the object doesn't rise to the top. Any suggestions would be appreciated.

Thanks,

Tom S.
5,397 views 2 replies
Reply #1 Top

Actually, you will want to use the following format for the OnStateChange callback:

Sub Object_OnStateChange(state)
  If state = "Riseup" Then
    Object.OnTop
    MsgBox("Hit")
  End If
End Sub

You need to of course treat the .State property as a string variable, as Riseup does not otherwise have any value within that scope. If you wanted, you could declare something like this in the global scope:

Const Private Riseup = "Riseup"

After making such a statement, you would be able to treat Riseup as you had.

The only thing you want to keep in mind is that the function header, for example:

Sub Object_OnStateChange(state)

treats whatever is within the parenthesis as a variable, so you couldn't actually put a concrete value here. This does allow you to put whatever you would like to use as a variable here, however, for example:

Sub Object_OnStateChange(strNewState)

-Mike
[Stardock Support]

Reply #2 Top
Mike,

Thank you so much for the reply. Looking back on it, this was really a dumb mistake.

Tom S.