by Peke » Thu Feb 04, 2010 1:41 am
Due above noted bug here is ShowModal Example where you can get what Radio Box is checked.
Code: Select all
Sub TestSCript
Script.Reload(Script.ScriptPath) 'Script Reload on INI Sheet so that updates can be checked
Dim Form
FormWidth=250
FormHeight=300
' Create the window to be shown
Set Form = SDB.UI.NewForm
Form.Common.SetRect 0, 0, FormWidth, FormHeight
Form.FormPosition = 4 ' Screen Center
Form.Caption = "IR Controls"
Form.StayOnTop = True
'Create a label at the top
Set TheLabel = SDB.UI.NewLabel(Form)
TheLabel.Caption = "Tree Node Name"
TheLabel.Common.Left = 10
TheLabel.Common.Top = 10
TheLabel.Common.Width = 150
TheLabel.Common.FontBold=1
SDB.Objects("IRFormLabel") = TheLabel
' Create a TreeList for selection of data to be shown
Set MTL = SDB.UI.NewTreeList(Form)
MTL.Common.SetRect 10, 30, (FormWidth-40), (FormHeight-100)
MTL.Common.ControlName = "CurrentlyPlaying"
SDB.Objects("IRFormNode") = MTL
Script.RegisterEvent MTL, "OnGetText", "MTLGetText"
Set node1 = MTL.AddNode(Nothing) ' nothing puts it as a parent
node1.TreeList.Common.ControlName = "CurrentlyPlaying1"
node1.UserText = "Currently Playing"
Set Node1Child1 = MTL.AddNode(node1)
Node1Child1.UserText = "Enqueue Album"
Node1Child1.CheckType = 3
Node1Child1.CheckState = 0
Set Node1Child1 = MTL.AddNode(node1)
Node1Child1.UserText = "Enqueue Album 2"
Node1Child1.CheckType = 3
Node1Child1.CheckState = 1
node1.Expanded = True 'this needs to be set here after all child nodes are added or node would not be expanded
Set CBut = SDB.UI.NewButton(Form)
CBut.Caption = "Check"
CBut.OnClickFunc = "CbutClick"
CBut.UseScript = Script.ScriptPath
Cbut.Common.SetRect 10, (FormHeight-60), 50, 20
'------------- If we only show the forms nods do not get Updated
'Form.Common.Visible = True ' Only show the form, don't wait for user input
'SDB.Objects("IRHelperForm") = Form ' Save reference to the form somewhere, otherwise it would simply disappear
'-------------
'------------- If we show form as modal than it gets updated.
Form.ShowModal
'-------------
Script.UnRegisterHandler "MTLGetText"
End Sub
Function MTLGetText(treenode, columnid)
If InEventHandler Then Exit Function
'Show Msg Box to see what will be shown in Tree Node
'Dim resi
'resi = SDB.MessageBox( treenode.UserText, mtError, Array(mbOk))
SDB.Objects("IRFormLabel").Caption = "Node Name: "&treenode.UserText
MTLGetText = treenode.UserText 'Return text of Node
End Function
Sub CbutClick( Btn) 'Check which ones are selected
Dim resi
Set treenode = SDB.Objects("IRFormNode") 'get treelist object
Set WorkingNode = treenode.FirstNode 'Get first treenode
While not WorkingNode is Nothing 'Set loop thrum all Tree Root Nodes
If WorkingNode.HasChildren Then 'Check if TreeNode Has Child Nodes in this case Radio button nodes
Set NextWorkingNode = WorkingNode.FirstChild 'Load first child nodes
Set NextWorkingNodeChild = NextWorkingNode 'Remember treenode object
While Not NextWorkingNodeChild Is Nothing 'create loop thrum childnodes
If NextWorkingNodeChild.CheckState = 1 Then resi = SDB.MessageBox( NextWorkingNodeChild.UserText&" Is Checked", mtInformation, Array(mbOk)) 'If checked show MSGBox
Set NextWorkingNodeChild = NextWorkingNodeChild.NextSibling 'get next child node
If Not NextWorkingNodeChild Is Nothing Then Set NextWorkingNode = NextWorkingNodeChild 'check if next childnode exist remember is last known node
Wend
Set WorkingNode = NextWorkingNode.NextNode 'retrieve next Root Node if exist
End If
Wend
End Sub
For others that want to test this you need to save this code to
Test form modal.vbs in
Scripts folder and add these lines to
Scripts.ini
Code: Select all
[SampleFormScript1]
Filename=Test form modal.vbs
Procname=TestSCript
Order=99
DisplayName=Create new Form Modal
Description=This will create New MM form and show it as modal
Language=VBScript
ScriptType=0
Due above noted bug here is ShowModal Example where you can get what Radio Box is checked.
[code]
Sub TestSCript
Script.Reload(Script.ScriptPath) 'Script Reload on INI Sheet so that updates can be checked
Dim Form
FormWidth=250
FormHeight=300
' Create the window to be shown
Set Form = SDB.UI.NewForm
Form.Common.SetRect 0, 0, FormWidth, FormHeight
Form.FormPosition = 4 ' Screen Center
Form.Caption = "IR Controls"
Form.StayOnTop = True
'Create a label at the top
Set TheLabel = SDB.UI.NewLabel(Form)
TheLabel.Caption = "Tree Node Name"
TheLabel.Common.Left = 10
TheLabel.Common.Top = 10
TheLabel.Common.Width = 150
TheLabel.Common.FontBold=1
SDB.Objects("IRFormLabel") = TheLabel
' Create a TreeList for selection of data to be shown
Set MTL = SDB.UI.NewTreeList(Form)
MTL.Common.SetRect 10, 30, (FormWidth-40), (FormHeight-100)
MTL.Common.ControlName = "CurrentlyPlaying"
SDB.Objects("IRFormNode") = MTL
Script.RegisterEvent MTL, "OnGetText", "MTLGetText"
Set node1 = MTL.AddNode(Nothing) ' nothing puts it as a parent
node1.TreeList.Common.ControlName = "CurrentlyPlaying1"
node1.UserText = "Currently Playing"
Set Node1Child1 = MTL.AddNode(node1)
Node1Child1.UserText = "Enqueue Album"
Node1Child1.CheckType = 3
Node1Child1.CheckState = 0
Set Node1Child1 = MTL.AddNode(node1)
Node1Child1.UserText = "Enqueue Album 2"
Node1Child1.CheckType = 3
Node1Child1.CheckState = 1
node1.Expanded = True 'this needs to be set here after all child nodes are added or node would not be expanded
Set CBut = SDB.UI.NewButton(Form)
CBut.Caption = "Check"
CBut.OnClickFunc = "CbutClick"
CBut.UseScript = Script.ScriptPath
Cbut.Common.SetRect 10, (FormHeight-60), 50, 20
'------------- If we only show the forms nods do not get Updated
'Form.Common.Visible = True ' Only show the form, don't wait for user input
'SDB.Objects("IRHelperForm") = Form ' Save reference to the form somewhere, otherwise it would simply disappear
'-------------
'------------- If we show form as modal than it gets updated.
Form.ShowModal
'-------------
Script.UnRegisterHandler "MTLGetText"
End Sub
Function MTLGetText(treenode, columnid)
If InEventHandler Then Exit Function
'Show Msg Box to see what will be shown in Tree Node
'Dim resi
'resi = SDB.MessageBox( treenode.UserText, mtError, Array(mbOk))
SDB.Objects("IRFormLabel").Caption = "Node Name: "&treenode.UserText
MTLGetText = treenode.UserText 'Return text of Node
End Function
Sub CbutClick( Btn) 'Check which ones are selected
Dim resi
Set treenode = SDB.Objects("IRFormNode") 'get treelist object
Set WorkingNode = treenode.FirstNode 'Get first treenode
While not WorkingNode is Nothing 'Set loop thrum all Tree Root Nodes
If WorkingNode.HasChildren Then 'Check if TreeNode Has Child Nodes in this case Radio button nodes
Set NextWorkingNode = WorkingNode.FirstChild 'Load first child nodes
Set NextWorkingNodeChild = NextWorkingNode 'Remember treenode object
While Not NextWorkingNodeChild Is Nothing 'create loop thrum childnodes
If NextWorkingNodeChild.CheckState = 1 Then resi = SDB.MessageBox( NextWorkingNodeChild.UserText&" Is Checked", mtInformation, Array(mbOk)) 'If checked show MSGBox
Set NextWorkingNodeChild = NextWorkingNodeChild.NextSibling 'get next child node
If Not NextWorkingNodeChild Is Nothing Then Set NextWorkingNode = NextWorkingNodeChild 'check if next childnode exist remember is last known node
Wend
Set WorkingNode = NextWorkingNode.NextNode 'retrieve next Root Node if exist
End If
Wend
End Sub
[/code]
For others that want to test this you need to save this code to [b]Test form modal.vbs[/b] in [b]Scripts[/b] folder and add these lines to [b]Scripts.ini[/b]
[code][SampleFormScript1]
Filename=Test form modal.vbs
Procname=TestSCript
Order=99
DisplayName=Create new Form Modal
Description=This will create New MM form and show it as modal
Language=VBScript
ScriptType=0[/code]