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