Object Required Error

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

cydog2001
Posts: 6
Joined: Thu Oct 04, 2012 8:44 pm
Location: In His Head

Object Required Error

Post by cydog2001 »

I'm working on a script to add and remove leading zeroes from selected items (including video), but I've run into a bit of a snag that's driving me completely nuts. For background, I'm using a portable install of MediaMonkey (at C:\MediaMonkey) with something like 50 songs and 20 videos added to it for testing.

What happens is this: I create a form, add some controls to it (thus far a few labels and a couple dropdowns), register the OnChange event for one of those dropdowns to enable/disable another dropdown and change the caption of one of the labels, then show the window. This part works fine. However when I change the first dropdown (ddFunction) and trigger the event sub (SwitchFunction), MM throws an "Object required" VBS error on the line where I attempt to enable or disable one of the dropdowns (ddHowMany.Common.Enabled = ...).

I think this means that ChildControl isn't returning an object, but that doesn't make sense to me as I have looked in other scripts that function fine and they seemingly use the exact same structure. Is this just one of the vagaries of scripting for MediaMonkey? Seriously, I'm confused as hell.

Here's my code:

Code: Select all

Sub ARLZ()
  Dim UI : Set UI = SDB.UI
  
  ' Create form
  Dim Form : Set Form = UI.NewForm 
  Form.Common.SetRect 100, 100, 360, 325
  Form.BorderStyle  = 2 'bsDialog
  Form.FormPosition = 4 'poScreenCenter
  Form.Caption = "Add/Remove Leading Zeroes"
  
  ' Add label to form
  Dim lblFunction : Set lblFunction = UI.NewLabel(Form) 
  lblFunction.Caption = "Function:"
  lblFunction.Common.Left = Int(Form.Common.Width/2) - Int(lblFunction.Common.Width/2) - 5
  lblFunction.Common.Top = 15 
  
  ' Add dropdown to form
  Dim ddFunction : Set ddFunction = UI.NewDropdown(Form)
  ddFunction.Common.SetRect 10, 40, 290, 25
  ddFunction.AddItem("Add leading zeroes")
  ddFunction.AddItem("Remove leading zeroes")
  ddFunction.ItemIndex = 0
  ' Register the OnChange event for this dropdown
  Call Script.RegisterEvent(ddFunction,"OnChange","SwitchFunction")
  
  ' Add label to form
  Dim lblHowMany : Set lblHowMany = UI.NewLabel(Form)
  lblHowMany.Caption = "How many?"
  lblHowMany.Common.Left = Int(Form.Common.Width/2) - Int(lblHowMany.Common.Width/2) - 5
  lblHowMany.Common.Top = 65
  
  ' Add dropdown to form
  Dim ddHowMany : Set ddHowMany = UI.NewDropdown(Form)
  ddHowMany.Common.SetRect 10, 90, 290, 25
  ddHowMany.AddItem("Tens (01 to 99)")
  ddHowMany.AddItem("Hundreds (001 to 999)")
  ddHowMany.AddItem("Thousands (0001 to 9999)")
  ddHowMany.ItemIndex = 0
  
  ' Add label to form
  Dim lblToFrom : Set lblToFrom = SDB.UI.NewLabel(Form)
  lblToFrom.Caption = "To:"
  lblToFrom.Common.Left = Int(Form.Common.Width/2) - Int(lblToFrom.Common.Width/2) - 5
  lblToFrom.Common.Top = 115
  
  ' Show dialog
  Form.ShowModal
  
  ' Unregister all events
  Call Script.UnregisterAllEvents
End Sub

Sub SwitchFunction(ddFunction)
  Dim FormC : Set FormC = ddFunction.Common.TopParent.Common
  Dim ddHowMany : Set ddHowMany = FormC.ChildControl("ddHowMany")
  Dim lblToFrom : Set lblToFrom = FormC.ChildControl("lblToFrom")
  
  ' Depending on what ddFunction is set to (either add or remove leading zeroes),
  ' enable or disable ddHowMany and change the Caption of lblToFrom to make more
  ' gramatical sense. ("Remove Leading Zeroes To" doesn't work.)
  Select Case ddFunction.ItemIndex 
    Case 0                                ' Add Leading Zeroes mode
      ddHowMany.Common.Enabled = True     ' Enable ddHowMany so that the user can choose how many leading zeroes should be added.
      lblToFrom.Caption = "To:"           ' Change the Caption of lblToFrom to "To:" so that it makes sense gramatically.
      
    Case 1                                ' Remove Leading Zeroes mode
      ddHowMany.Common.Enabled = False    ' Disable ddHowMany as it is irrelevant in this mode.
      lblToFrom.Caption = "From:"         ' Change the Caption of lblToFrom to "From:" so that it makes sense gramatically.
  End Select
End Sub
The things that will destroy America are prosperity-at-any-price, peace-at-any-price, safety-first instead of duty-first, the love of soft living, and the get-rich-quick theory of life.

--Theodore Roosevelt
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Object Required Error

Post by trixmoto »

You need to use ControlName to label the object before you can use ChildControl to get it.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Object Required Error

Post by trixmoto »

I've just amended the wiki to make this clearer.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
cydog2001
Posts: 6
Joined: Thu Oct 04, 2012 8:44 pm
Location: In His Head

Re: Object Required Error

Post by cydog2001 »

Well, that makes sense. I'm kicking myself right now for not seeing that, but I'm glad the wiki is more clear now.

Thanks for your help.
The things that will destroy America are prosperity-at-any-price, peace-at-any-price, safety-first instead of duty-first, the love of soft living, and the get-rich-quick theory of life.

--Theodore Roosevelt
trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Re: Object Required Error

Post by trixmoto »

Glad I could help :)
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Post Reply