Skip to main content
1-Visitor
December 30, 2011
Solved

Questions on scripting a list box or combo box

  • December 30, 2011
  • 3 replies
  • 12085 views

Hi all,

I need to make an automatically updating list box and I've provided an example worksheet to show how far along I am and where I would like to go. The biggest issue is that I just started learning VB today. I understand everything in the current script that I am using, which I got from a previous thread.

Here's my wishlist:

1. By default the listbox displays multiple options, but I would like to make it like a pulldown menu that shows a single option.

2. Currently the cursor selection value is given as the output. It would be handy to output the text or a value that the text represents.

I need Mathcad to do this because other users may modify the data in the worksheet and the listbox needs to respond to that change.

Please see the attached Mathcad worksheet and thank you in advance for any help or advice that you can provide. Even if someone could direct me to a place that I can go online to learn about scripting commands that would help me script better in Mathcad, that would be extremely appreciated.

Best answer by RichardJ

I am trying to take in two vectors as inputs. One vector containing a list of names and another vector that has numeric values for those names. I want to create a list box or combo box that mimics the "What I Would Like:" in the previous script that I posted. Basically that the listbox contains list of names and then outputs a unique value that is linked to each name (by way of a second vector that I can input into the list box.

ListBox.CurSel gives you the index into the list. So just pick off the correct entry in Values as the output:

Outputs(0).Value = Values(ListBox.CurSel), as you show below.

I saw that an array "ListBox" was created and populated with the list of names from a vector input.

ListBox is not an array, it is an object. In fact, it is the listbox object that is on the Mathcad worksheet.

I also noticed the hanging next as well, but I thought it had some use that was above my comprehension. I've deleted it from my script.

The problem was not that you had a Next, it's that you didn;t have two of them. All loops are terminated by a Next statement (just as all Ifs are terminated by an End If statement).

  • How to create the array: Dim Values()?
  • How to populate the array... a) 1-dimensional vectors: Values.Addstring(Inputs(1).Value(i)? b) From a 2-D array... no clue?
  • How to output the correct value: Outputs(0).Value = Values(ListBox.CurSel)?

Dim Values(). This creates the array, with an undefined number of elements

To populate it

Values = Inputs(0).Values

Your output statement will work fine.

I'm lost in translation, I think.

I hate to say it, but I think perhaps you are lost in the basics. I get the impression that you are not just new to VBscript, but new to programming in general. If you want to program in any language that works with objects (which is just about every modern language) then you need to understand what objects are. You also need to learn the syntax of the specific language: the different variable types, the syntax for loops, the syntax for conditional statements, etc. You need to get a book and read up on this stuff, because without the basics you will have difficulty even modifying existing scripts, let alone writing ones from scratch.

3 replies

24-Ruby III
December 31, 2011

Andrew Hirsch wrote:

...Even if someone could direct me to a place that I can go online to learn about scripting commands that would help me script better in Mathcad, that would be extremely appreciated...

Hello!

Maybe this will help you (Visual Basic page on Microsoft site): http://msdn.microsoft.com/en-us/vstudio/hh388568

19-Tanzanite
December 31, 2011
Maybe this will help you (Visual Basic page on Microsoft site): http://msdn.microsoft.com/en-us/vstudio/hh388568

VB comes in many flavors. There is VBscript, VBA, the older VB6, etc, and VB in Visual Studio. VB in Visual Studio is quite different to the others, and very different to VBscript.

1-Visitor
December 31, 2011

Richard has uploaded many worksheets which may be of help. Please see link below.

http://communities.ptc.com/docs/DOC-1071#comment-1335

Mike

19-Tanzanite
December 31, 2011

1. By default the listbox displays multiple options, but I would like to make it like a pulldown menu that shows a single option.

What you show in the second example is not a listbox, it's a combobox. Unfortunately, the only Mathsoft combobox control is a web control, which cannot be programmed. One option is to shrink the listbox and add a scrollbar (I didn't say it was a good option). The only other thing you could do would be to program a different combobox control, such as the MSForms 2.0 combobox. The problem with doing that is that the control will not work on any computer that does not have the corresponding ActiveX control installed (MSForms 2.0 controls are installed with Office). If you do that, bear in mind that the properties and methods of MSForms 2.0 controls do not have the same names as the Mathsoft controls!

2. Currently the cursor selection value is given as the output. It would be handy to output the text or a value that the text represents.

That's easy enough.

Please see the attached Mathcad worksheet and thank you in advance for any help or advice that you can provide. Even if someone could direct me to a place that I can go online to learn about scripting commands that would help me script better in Mathcad, that would be extremely appreciated.

Mike has pointed you to a document with many examples. Mostly, anyway. He actually pointed you to a comment, so here's a link to the document itself: Extra Components.mcd

You can read about VBscript here: http://msdn.microsoft.com/en-us/library/t0aew7h6

I also recommend the book "VBscript in a Nutshell", by Matt Childs et. al.

24-Ruby III
December 31, 2011

Richard Jackson wrote:

...I also recommend the book "VBscript in a Nutshell", by Matt Childs et. al...

It's available online on "Google books": http://books.google.ru/books?id=NLpuZSatG3QC&printsec=frontcover&hl=ru