Skip to main content
17-Peridot
September 24, 2015
Solved

How do I compare variable names in MC15?

  • September 24, 2015
  • 18 replies
  • 7465 views

Hello folks,

this is about a basic issue hence no example sheet.

For a lengthy calculation I'd like to read in parameters from excel. As this excel sheet is lenghty as well I want to check first whether the parameters in the Excel sheet match the parameters in my MatchCad sheet (naming and order of parameters). I'm thinking along the lines of making a one-to-one comparison of variable names (not the variable values!) in order to verify a match.

Does anybody has an idea how to conduct such a comparison?

Thanks in advance for any idea

Raiko

Best answer by MikeArmstrong

Raiko Milanovic wrote:

😞

Just an idea I got: might it be possible to read in the mathcad parameters into a textbox and do the comparison via VB? I'm thinking of a property called "GetText" but I'm unsure on how to apply it.

Raiko

I am still unsure if that will work with subscripts. I think the approach I mentioned above, and Stuart's detailed explanation is the best way to go.

Mike

18 replies

1-Visitor
September 24, 2015

Could you first call the parameters you want to check into Mathcad, not the whole sheet, and then perform the check?

Mike

Raiko17-PeridotAuthor
17-Peridot
September 24, 2015

Hello Mike,

that's exactly what I want to do. Call the parameters - then compare them to the MC parameters. However, the MC parameters are variables. The content of the variables I could convert to a string and compare to some other string but not the variables themselves.

Any ideas?

Raiko

1-Visitor
September 24, 2015

Probably best posting an replica problem if you can. I am sure what you are describing can be achieved.

23-Emerald V
September 24, 2015

Raiko Milanovic wrote:

Hello folks,

this is about a basic issue hence no example sheet.

For a lengthy calculation I'd like to read in parameters from excel. As this excel sheet is lenghty as well I want to check first whether the parameters in the Excel sheet match the parameters in my MatchCad sheet (naming and order of parameters). I'm thinking along the lines of making a one-to-one comparison of variable names (not the variable values!) in order to verify a match.

Does anybody has an idea how to conduct such a comparison?

How about using an array with the variable names in and iterating through that?  You could hide it in a collapsed Area once you've got it debugged and just set a variable to give you the result of the check (eg, a simple "OK" if everything's OK or a list of variables that aren't playing nicely).  That is, something along the lines of:

Stuart

Raiko17-PeridotAuthor
17-Peridot
September 24, 2015

Thank you Stuart.

Neat idea, but then I do need to define the parameters twice. Once as a variable and once as a string for performing a check as you proposed it. This is error prone therefore I'd like to use only the variable names. Perhaps some nifty VB code does the trick?

Raiko

23-Emerald V
September 24, 2015

Raiko Milanovic wrote:

Thank you Stuart.

Neat idea, but then I do need to define the parameters twice. Once as a variable and once as a string for performing a check as you proposed it. This is error prone therefore I'd like to use only the variable names. Perhaps some nifty VB code does the trick?

Raiko

Errare Humane Est.   The most obvious way to do that would seem to be to get the Excel array of variable names and pass it to the VBScript.  Then iterate through the Math regions until you find variable names you want (I don't know how you guarantee that there are no other variables (such as index variables) or how you would identify them (Tagging them is an option, but then you've got an error-prone maintenance task if you need to change the structure of the worksheet).  An alternative, but vary much along the same lines, is to use a file read function to hunt for the corresponding variable definition xml strings in the worksheet's source code.

Of course, there could be a mistake in any code that misses certain cases!

Stuart

1-Visitor
September 25, 2015

Maybe it won't work for what you need, but consider an alternate approach: reference Mathcad from within Excel instead of referencing Excel from within Mathcad.

- Add a column in Excel with the Mathcad variable names (R.mM, R.p02, D, ...)

- Within Excel add VB routine to SetValue for each of these variables, calculate the worksheet, then GetValue.