Eyal wrote:By "ending the session" I meant ending MediaMonkey. Global variables will retain their values until then.
Well, I misunderstood your meaning of "ending the session".
Global variables will not retain their values until ending MM.
Code: Select all
Option Explicit
Sub OnStartUp()
Dim Menu
Set Menu = SDB.UI.AddMenuItem(SDB.UI.Menu_TbSearch, 1, 0)
Menu.UseScript = Script.ScriptPath
Menu.IconIndex = 27
Menu.OnClickFunc = "TEST1"
Menu.Caption = "TEST 1"
Set Menu = SDB.UI.AddMenuItem(SDB.UI.Menu_TbSearch, 1, 0)
Menu.UseScript = Script.ScriptPath
Menu.IconIndex = 27
Menu.OnClickFunc = "TEST2"
Menu.Caption = "TEST 2"
End Sub
Dim KeepVariable
Sub TEST1(Menu)
KeepVariable = False
msgbox("TEST 1")
' session "ends"
End Sub
Dim Test2Timer
Sub TEST2(Menu)
msgbox("TEST 2")
msgbox("alive? "& KeepVariable)
KeepVariable = True
' keep session alive
Set Test2Timer = SDB.CreateTimer(0)
Script.RegisterEvent Test2Timer, "OnTimer", ""
Test2Timer.Enabled = False
End Sub
The variable that I need to keep alive has an object, so an INI won't help.
In my tests, if an object is not assigned to SDB.Objects after the script "ends", it's lost.
Unless, of course, I prevent the script from "ending" by registering a dummy timer.
This object is the one that would trigger the event that calls a sub for the script to continue, if it dies, no trigger.
There are many global variables being shared by multiple subs, and the event could be triggered thousand of times, very quickly. so saving and loading every time would be too messy.
Eyal wrote:it's not a good idea (it's against structural programming) to have code outside of subs or functions (though variables are OK).
I did not say anything about code outside of subs or functions.
[quote="Eyal"]By "ending the session" I meant ending MediaMonkey. Global variables will retain their values until then.[/quote]
Well, I misunderstood your meaning of "ending the session".
Global variables will not retain their values until ending MM.
[code]Option Explicit
Sub OnStartUp()
Dim Menu
Set Menu = SDB.UI.AddMenuItem(SDB.UI.Menu_TbSearch, 1, 0)
Menu.UseScript = Script.ScriptPath
Menu.IconIndex = 27
Menu.OnClickFunc = "TEST1"
Menu.Caption = "TEST 1"
Set Menu = SDB.UI.AddMenuItem(SDB.UI.Menu_TbSearch, 1, 0)
Menu.UseScript = Script.ScriptPath
Menu.IconIndex = 27
Menu.OnClickFunc = "TEST2"
Menu.Caption = "TEST 2"
End Sub
Dim KeepVariable
Sub TEST1(Menu)
KeepVariable = False
msgbox("TEST 1")
' session "ends"
End Sub
Dim Test2Timer
Sub TEST2(Menu)
msgbox("TEST 2")
msgbox("alive? "& KeepVariable)
KeepVariable = True
' keep session alive
Set Test2Timer = SDB.CreateTimer(0)
Script.RegisterEvent Test2Timer, "OnTimer", ""
Test2Timer.Enabled = False
End Sub
[/code]
The variable that I need to keep alive has an object, so an INI won't help.
In my tests, if an object is not assigned to SDB.Objects after the script "ends", it's lost.
Unless, of course, I prevent the script from "ending" by registering a dummy timer.
This object is the one that would trigger the event that calls a sub for the script to continue, if it dies, no trigger.
There are many global variables being shared by multiple subs, and the event could be triggered thousand of times, very quickly. so saving and loading every time would be too messy.
[quote="Eyal"]it's not a good idea (it's against structural programming) to have code outside of subs or functions (though variables are OK).[/quote]
I did not say anything about code outside of subs or functions.