For example, Steegy has this ...
Code: Select all
Form.FormPosition = mmFormScreenCenter
TIA
Code: Select all
Form.FormPosition = mmFormScreenCenter
Code: Select all
So, it is not necessary to declare a constant above its usage.
Code: Select all
Dim testvariable
testvariable = "This is only a test"
(I missed that earlier. ) That must mean it is safe to assume it exists. It's too bad they didn't put many of the constants from the documentation in there.“MediaMonkey init.vbs” file is always executed before your script and therefore it contains some constants that can be later used in your script.
I am not really understanding that stuff. Does it have something to do with the very strange behavior here:Steegy wrote:"MediaMonkey init.vbs" is included (each time) for each script that is executed. As it is merely included, the variables (constants) aren't "shared" with other scripts and you can't globally change them (therefore there's SDB.Objects).
Variables defined for the complete script scope can be reached by code that is called by an event using the new scripting mechanism (recommended, only isn't possible for option sheets). These variables can NOT be used by an event using the old event mechanism (only use this for now for option sheets).
Code: Select all
Option Explicit
Dim objSDB, objSSL, frmForm, btnShowVersionHi, btnShowCount
Sub onStartup
Set objSDB = SDB
Set objSSL = SDB.SelectedSongList
Set frmForm = SDB.UI.NewForm
Set btnShowVersionHi = SDB.UI.NewButton(frmForm)
btnShowVersionHi.Common.SetRect 10, 10, 100, 30
btnShowVersionHi.Caption = "VersionHi"
btnShowVersionHi.UseScript = Script.ScriptPath
btnShowVersionHi.OnClickFunc = "ShowVersionHi"
Set btnShowCount = SDB.UI.NewButton(frmForm)
btnShowCount.Common.SetRect 10, 50, 100, 30
btnShowCount.Caption = "ShowCount"
Script.RegisterEvent btnShowCount, "OnClick", "ShowCount"
ShowVersionHi(btnShowVersionHi) ' This works this time!
ShowCount ' This works, too!
frmForm.ShowModal
' But when I click on the buttons on the form, the VersionHi one
' doesn't work because objSDB supposedly doesn't exist! Yet,
' ojbSSL still exists when I click on the ShowCount button.
Script.UnregisterAllEvents
End Sub
Sub ShowVersionHi(btnShowVersionHi)
MsgBox "VersionHi = " & objSDB.VersionHi
End Sub
Sub ShowCount()
MsgBox objSSL.Count & " songs are selected."
End Sub
Thanks for trying to help. All I was trying to do, though, was demonstrate some strange behavior that I don't understand that involves variable scope issues. The code serves no useful purpose beyond that. I probably confused things by referring to two different objects. The same issues should apply to any SDB object AFAIK.Peke wrote:Are you sure you are doing it like you want?
I set it up that way so someone could just paste it into a file and run it to see what I am talking about without messing with the scripts\scripts.ini file. It doesn't have to be that way - the same problems exist no matter how you start the script, or what the Sub is called. As it is, objSSL.Count should be zero, because nothing could be selected yet on Startup. I just wanted to see if I got an error trying to refer to the objSSL variable. First the script displays the message saying objSSL.count is zero, but then I get a VBScript error saying objSSL doesn't exist when I click the button, but only if I set up the button the way I did the other button. This doesn't make sense to me.Peke wrote:Sub onStartup is executed on MM start and objSSL will have same value untill you close MM and may produce wrong value.
Right. I just wanted to see if I could use objSDB without generating an vbScript error.Peke wrote:Also no need to use Set objSDB = SDB as SDB is parsed to each running of script and you can always access it.
Oh! So, basically that means that what Steegy said a few posts ealier:Peke wrote:Good points.
You dint saved objSSL object (I didn't payed attencion on that) and thats why it do not exist in second pass (reason it is not initialized) When you init Some Var save it for later using Objects and you will always get Zoro.
... is relevant to what I am doing after all.Steegy wrote:Variables defined for the complete script scope can be reached by code that is called by an event using the new scripting mechanism (recommended, only isn't possible for option sheets). These variables can NOT be used by an event using the old event mechanism (only use this for now for option sheets).
So, I guess that means I was using what Steegy called the "old mechanism" with my top button, and the "new mechanism" with the bottom button. And that's why the bottom button worked, while the top one didn't.There are still 2 scripting mechanisms available:
* Using the (mostly deprecated) old event mechanism (using Control.OnClickFunc and Control.UseScript), your global variables aren't remembered in the event handlers (e.g. kind of like the script is reopened). For those scripts, you had to use ParentControl.ChildControl("control name") or save object references to SDB's Objects dictionary.
* Using the new event mechanism, your global variables are remembered so you can use their values in the event handlers. The Objects dictionary is now only necessary to communicate/store object references between different scripts.
==> So always use the new event mechanism where you can. Only for option panels (sheets) this is not yet possible. There you'll need to store values between the main program and the event handlers in SDB.Objects, in the INI or in the Registry.
Yes, because that's *completely* useless. Variable declarations that go out of scope (here the scope of the CloseDown procedure) are automatically gotten rid of (in virtually any programming language).Is there any particular reason you didn't "Set WB = Nothing" in CloseDown?
I disagree somewhat. Yes, mistakes will happen, but IMO, people should not write "'X'" in the wiki unless they are confident that 'X' is really true. It is worse to mislead someone than it is to leave them unknowing.Steegy wrote:Feel free to change things in the wiki (as long as it's mostly correct); you might be in a situation that makes it much easier to explain stuff for new scripters, as for people who already know the stuff, some necessary and important details (?!) might look "obvious". If you get something wrong, don't worry, it'll get fixed.