change control caption outside a form [#9780]

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: change control caption outside a form [#9780]

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

by Peke » Mon Oct 15, 2012 4:20 pm

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?

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

by allart » Fri Oct 05, 2012 2:03 am

Works. Thanks a lot!

Re: change control caption outside a form

by Peke » Thu Oct 04, 2012 4:38 pm

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

change control caption outside a form [#9780]

by allart » Thu Oct 04, 2012 4:51 am

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 

Top