INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

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

A Fan of EngTips, share the knowledge

RE: ListBox, VB Script, MathCad15

(OP)
For future reference of those who may be reading the thread for help with their MathCad challenges. In MathCad there is a resource I found, Help > Developer's Reference, click on "Scripting Custom OLE Objects". It provide some information and code/script details

A Fan of EngTips, share the knowledge

RE: ListBox, VB Script, MathCad15

(OP)
For future reference of those who may be reading the thread for help with their MathCad challenges.

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

I really like it when people come back and share solutions they find on their own. Thank you.

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources


Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close