change control caption outside a form [#9780]

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

Moderators: Gurus, Addon Administrators

allart
Posts: 3
Joined: Thu Oct 04, 2012 4:39 am

change control caption outside a form [#9780]

Post by allart »

Hi,

I just started with scripting in MM. I have a question, which I just can't find an answer to.
Basically, I would like to change the caption of a label by pressing another button.
With the next code I get the OLE error: 800a01C2, followed by a mismatch error.

Can someone tell what I am doing wrong here?

tnx,
Allart

Code: Select all

Sub OnStartup 
  Set UI = SDB.UI 
  
  ' Create the window to be shown 
  Set Form = UI.NewForm 
  Form.FormPosition = 4   ' Screen Center 
  Form.Caption = "Test Change labels" 
  
  Set Lbl2 = UI.NewLabel(Form) 
  Lbl2.Common.ControlName = "Lbl2" 
  Lbl2.Common.SetRect 10, 10, 100, 16 
  Lbl2.Caption = "Change This Label"
  
  Set Btn2 = UI.NewButton(Form) 
  Btn2.Common.ControlName = "Btn2" 
  Btn2.Common.SetRect 10, 40, 80, 25 
  Btn2.Caption = "Test" 
  Script.RegisterEvent Btn2, "OnClick", "Btn2Click" 
  
  Form.ShowModal
  SDB.Objects("Form1") = Form1
End Sub 

Sub Btn2Click (Form)
  Set frm1 = SDB.Objects("Form1")
  Set label2 = frm1.ChildControl("Lbl2")
  label2.Caption = "Label Changed"

  SDB.MessageBox "Clicked Button", mtInformation, Array(mbOk)
  ' add code to change Caption of Lbl2
End Sub 
Peke
Posts: 17486
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: change control caption outside a form

Post by Peke »

Here is corrected working one:

Please note that at MM is not yet fully Initialized it is better to save object instead of whole form and also use Common Object instead Button object itself.

I also Added http://www.ventismedia.com/mantis/view.php?id=9780 for further checking, if you stumble apron more issues with other objects let me know in PM or Here please so that I can update bug on Mantis.

Code: Select all

    Sub OnStartup
      Set UI = SDB.UI
     
      ' Create the window to be shown
      Set Form = UI.NewForm
      Form.FormPosition = 4   ' Screen Center
      Form.Caption = "Test Change labels"
     
      Set Lbl2 = UI.NewLabel(Form)
      Lbl2.Common.ControlName = "Lbl2"
      Lbl2.Common.SetRect 10, 10, 100, 16
      Lbl2.Caption = "Change This Label"
      
      SDB.Objects("MyLbl2") = Lbl2
     
      Set Btn2 = UI.NewButton(Form)
      Btn2.Common.ControlName = "Btn2"
      Btn2.Common.SetRect 10, 40, 80, 25
      Btn2.Caption = "Test"
      Script.RegisterEvent Btn2.Common, "OnClick", "Btn2Click"
     
      Form.ShowModal

    End Sub

    Sub Btn2Click (Form)
      Set label2 = SDB.Objects("MyLbl2")
      label2.Caption = "Label Changed"

      'SDB.MessageBox "Clicked Button", mtInformation, Array(mbOk)
      ' add code to change Caption of Lbl2
    End Sub
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
allart
Posts: 3
Joined: Thu Oct 04, 2012 4:39 am

Re: change control caption outside a form [#9780]

Post by allart »

Works. Thanks a lot!
Peke
Posts: 17486
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: change control caption outside a form [#9780]

Post by Peke »

FYI I updated http://www.mediamonkey.com/wiki/index.p ... s::OnClick in regards of investigation within http://www.ventismedia.com/mantis/view.php?id=9780

Hope it is more clear now?
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
Post Reply