ListBox, VB Script, MathCad15
ListBox, VB Script, MathCad15
(OP)
Hello,
I'm not very experienced with MathCad15 or programming. I'm looking for advice and resources on using Listbox and VBscript.
In MathCad I created a Matrix and propagated it with values.
I then created a ListBox. I want to edit the script of the list box so that the ListBox shows the first column of my matrix for possible selections. The ListBox will Output will be the matrix index of the selected item (click on the list box, select one of the options, MathCad variable will be assigned that value).
I'm having troubling figuring out the following
How to pass the MathCad Matrix into the VBscript, if I write click on the List Box, it shows options such as "Add input variable". What types of data can be entered (integer, floating point, alphanumeric strings, ...)?
How to create a Matrix in VBscript [I can create an array, code: Dim array(#,#,#,...)]
How to pass the index number out of the VBscript? if I write click on the List Box, it shows options such as "Add output variable". What types of data can be entered (integer, floating point, alphanumeric strings, ...)?
There are several sections to the VBscript in the List Box, as follows (What does each routine or sub-routine do?):
Rem Initialize List Box
ListBox.ResetContent()
Rem Add Strings here as needed
ListBox.AddString(1)
ListBox.AddString(2)
ListBox.AddString(3)
Rem Initialize Selection If desired
ListBox.CurSel = 0
Sub ListBoxEvent_Start()
End Sub
Sub ListBoxEvent_Exec(Inputs,Outputs)
Outputs(0).Value = ListBox.CurSel + 1
End Sub
Sub ListBoxEvent_Stop()
Rem TODO: Add your code here
End Sub
Sub ListBox_SelChanged()
ListBox.Recalculate()
End Sub
Sub ListBox_DblClick()
ListBox.Recalculate()
End Sub
Thank you in advance for any help you might be able to provide
I'm not very experienced with MathCad15 or programming. I'm looking for advice and resources on using Listbox and VBscript.
In MathCad I created a Matrix and propagated it with values.
I then created a ListBox. I want to edit the script of the list box so that the ListBox shows the first column of my matrix for possible selections. The ListBox will Output will be the matrix index of the selected item (click on the list box, select one of the options, MathCad variable will be assigned that value).
I'm having troubling figuring out the following
How to pass the MathCad Matrix into the VBscript, if I write click on the List Box, it shows options such as "Add input variable". What types of data can be entered (integer, floating point, alphanumeric strings, ...)?
How to create a Matrix in VBscript [I can create an array, code: Dim array(#,#,#,...)]
How to pass the index number out of the VBscript? if I write click on the List Box, it shows options such as "Add output variable". What types of data can be entered (integer, floating point, alphanumeric strings, ...)?
There are several sections to the VBscript in the List Box, as follows (What does each routine or sub-routine do?):
Rem Initialize List Box
ListBox.ResetContent()
Rem Add Strings here as needed
ListBox.AddString(1)
ListBox.AddString(2)
ListBox.AddString(3)
Rem Initialize Selection If desired
ListBox.CurSel = 0
Sub ListBoxEvent_Start()
End Sub
Sub ListBoxEvent_Exec(Inputs,Outputs)
Outputs(0).Value = ListBox.CurSel + 1
End Sub
Sub ListBoxEvent_Stop()
Rem TODO: Add your code here
End Sub
Sub ListBox_SelChanged()
ListBox.Recalculate()
End Sub
Sub ListBox_DblClick()
ListBox.Recalculate()
End Sub
Thank you in advance for any help you might be able to provide
A Fan of EngTips, share the knowledge
RE: ListBox, VB Script, MathCad15
A Fan of EngTips, share the knowledge
RE: ListBox, VB Script, MathCad15
MathCad, Help > QuickSheets Contents, click on “Programing”, scroll down and click “Mathsoft Controls”
Then scroll down to the example you’re interested in, left click and select “Edit Script…”
Here's code from their example
Sub ListBoxEvent_Start()
sel = ListBox.CurSel
ListBox.ResetContent()
mats = Worksheet.GetValue("Material")
If mats = "Steel" Then
ListBox.AddString "SAE 950 (low alloy)"
ListBox.AddString "SAE 1025 (low carbon)"
ListBox.AddString "SAE 1045 (medium carbon)"
ListBox.AddString "SAE 1095 (high carbon)"
ElseIf mats = "Wrought Iron" Then
ListBox.AddString "Single Species"
ElseIf mats = "Cast Iron" Then
ListBox.AddString "class 20"
ListBox.AddString "class 25"
ListBox.AddString "class 30"
ListBox.AddString "class 35"
ListBox.AddString "class 40"
Else
ListBox.AddString "Unknown Material"
End If
ListBox.CurSel = sel
End Sub
Sub ListBoxEvent_Exec(Inputs,Outputs)
sel = ListBox.CurSel
' Force sel to be a valid value, rather than -1
If sel < 0 Then
sel = 0
End If
' Highlight the selected value
ListBox.CurSel = sel
mats = Inputs(0).Value
If sel >= 0 Then
Outputs(0).Value = ListBox.GetText(sel)
If mats = "Steel" Then
If sel = 0 Then
Outputs(1).Value = 70
ElseIf sel = 1 Then
Outputs(1).Value = 103
ElseIf sel = 2 Then
Outputs(1).Value = 182
ElseIf sel = 3 Then
Outputs(1).Value = 213
End If
ElseIf mats = "Wrought Iron" Then
Outputs(1).Value = 54
ElseIf mats = "Cast Iron" Then
Outputs(1).Value = 20 +5*sel
Else
Outputs(1).Value = 0
End If
Else
Outputs(0).Value = "No selection"
Outputs(1).Value = "N/A"
End If
End Sub
Sub ListBoxEvent_Stop()
Rem TODO: Add your code here
End Sub
Sub ListBox_SelChanged()
ListBox.Recalculate()
End Sub
Sub ListBox_DblClick()
ListBox.Recalculate()
End Sub
______________________________________________________________________________
I found this Website helpful for VBscript systax information, https://ss64.com/vb/syntax.html
Happy coding!
A Fan of EngTips, share the knowledge
RE: ListBox, VB Script, MathCad15
David Simpson, PE
MuleShoe Engineering
In questions of science, the authority of a thousand is not worth the humble reasoning of a single individual. Galileo Galilei, Italian Physicist