cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Convert string to variable definition

0 Kudos

Convert string to variable definition

Mona,

I am dating this request March 1, so it will be included.

There was a thread some time ago about a function like "str2var"

i.e. take a string and convert it to a variable definition. I know there are work arounds, but have not found one simple enough:

I have a matrix with column headings, I want to be able to rearrange the columns as needed and use the heading as a variable, numerically locating the column so that I could use the column heading as variable in other functions, indicating which column is to be used. Not only do I want to rearrange, but be able to add columns with a new heading, as yet undetermined. I would use this many,many times in the same worksheet and in many, many worksheets.

Thanks,

Wayne

58 Comments
RichardJ
19-Tanzanite

I don't follow you. If you create a variable at the top of the worksheet, say "MyVar", it's not going to be used for anything unless you already wrote the rest of the worksheet to use that variable name.

wayne
2-Guest

Richard,
Thanks for opening the door.

Attached is what I am looking for,

Thanks

RichardJ
19-Tanzanite

There is no "attached", so I guess "job done".

wayne
2-Guest

Sorry Richard, was in a hurry.

wayne
2-Guest
RichardJ
19-Tanzanite

OK, for the matrix I see what you want. It could be done, but (as you noted) not easily. If the matrix function, in this case IBC06, is in a reference worksheet then we would need to have a scripted component that loaded that worksheet (I think you would have to supply the name of the sheet though; it can't be obtained programmatically), found the correct region, got the name from the XML of the region, then modified the XML of the region where LCmat is assigned to put in the correct matrix name.

I still don't get it with bD and bS though. The subsequent statements assume those variable names. If you change them programmatically to something else then the assignments to P and Comb31 will no longer work. You would have to programmatically go through the entire worksheet doing a search and replace operation.

wayne
2-Guest

Richard,
Thanks for the response:

1) The file is always referenced at the beginning of the job, so I don't need to look for it.

2) The variables in the matrix are assigned in the job worksheet, so LCmat must be constructed there. (and there may be more than one)

3) The short examples were done for example, they represent types of loads that may or may not be on a particular member. It I am specifying several loads that are dead loads, they are in the bD calss, and the factors under that class in the matrix apply for combining with other load classes.

It is convient to have a class variable equal to the column of the LCmat matrix. i.e. bD=2, or whatever the column with "bD" as the heading. That way, when working with many types of loads, for the desing of many beams, columns, footings, ect. It is easy to keep track or what load class I am dealing with.

For another example, I track reactions from previously designed elements that load others, and I need to keed the reactions sepearated into the individule classes because different load combinations may apply for different elements.

So I might have R1<bD> which is a vector of dead load reactions at end 1 of all the previously designed beams. Then I could apply load to a supporting member as R1.5,bD, (Reaction from end 1 of beam 5, of the bD class)

I already do all of this, except I must manually make changes assigning the column heading to the correct column number. It would be nice to have a short program, using a "str2var" funciton.

I am addressing multiple users and they may want to order the matrix differently or add categories depending on the job specifics, and I am concerned that the re-assignment may be missed or a column not assigned correctly, which can result in things being unpleasently squashed.

Thanks,

Wayne

mzeftel
1-Newbie

Wayne and all,

I addd my comment both so that everyone would know that your suggestions are being captured, and so I know what I've captured so far.

This thread is getting very long, which is why I'd recommend starting a new one.

It would also be helpful to have a separate forum for feature suggestions, so people can comment on each suggestion in a separate thread.

I'll see what we can do about that.

Mona

RichardJ
19-Tanzanite
It would also be helpful to have a separate forum for feature suggestions, so people can comment on each suggestion in a separate thread.

I 100% agree. I think we used to have one of those, didn't we?

A separate forum for suspected bugs would be handy too, so each suspected bug is a separate thread

MikeArmstrong
5-Regular Member

str2var("bD",5) then bD=5,

Nice suggestion Wayne,

I had a similar problem to when helping another member yesterday. He was trying to pass the variables names to a text file but as a string with the value included.

var2str(bD=5) = "bD=5" or something similar.

Mike

RichardJ
19-Tanzanite
I had a similar problem to when helping another member yesterday. He was trying to pass the variables names to a text file but as a string with the value included.

Yes, I saw that thread. I thought we might end up getting into getting the XML of regions again, but he never replied to you (or perhaps I just missed it?).

var2str(bD=5) = "bD=5" or something similar.

Right, but Wayne want's the opposite. For the matrix assignment (where the variable name you are creating is on the right of the assignment) I can see the potential utility of that, but I don't get the other bit. Other people have asked for this too though, for various reasons. Tom created a worksheet that will do it by modifying the XML of a math region.

MikeArmstrong
5-Regular Member

Yes, I saw that thread. I thought we might end up getting into getting the XML of regions again, but he never replied to you (or perhaps I just missed it?).

No, you didn't miss it he no reply as of yet.

I am right to assume that this have been a long standing request?

Mike

RichardJ
19-Tanzanite
I am right to assume that this have been a long standing request?

It's been asked for more than once, and Tom created a worksheet that can do it. I have never understood what you would do with the ability to create variables though. I've asked several times, in different threads, what the point of it is, and don't recall getting an answer. Say I create a variable "XYZ" at the top of the worksheet, and assign some number to it. That does nothing unless there is an expression somewhere in the worksheet that depends on the variable XYZ. But if I created such an expression I know I need to assign a value to XYZ, so why not just create the variable assignment by typing it in? Why create it programmatically?

MikeArmstrong
5-Regular Member

I wasn't directly asking for it, I was more referring to a thread I have been contributing too where I had to manually type the variable name being passed.

I think a variable name - String would be a good function as it would allow variable names to be passed to results tables without having to use the double parenthesis.

Mike

RichardJ
19-Tanzanite

2) The variables in the matrix are assigned in the job worksheet, so LCmat must be constructed there. (and there may be more than one)

When you construct LCmat, what exactly is it you want to change? The name of the function on the RHS of the assignment?

There is a problem changing anything in the referenced worksheet. Those changes are not seen by the referencing worksheet unless you specifically recalculate the reference by selecting it and hitting F9. Recalculating the entire referencing worksheet will not update the reference. There is no way to programmatically recalculate a specific region though.

I already do all of this, except I must manually make changes assigning the column heading to the correct column number.

Maybe I misunderstand what you want to do. In the assignment bD:=3 do you want to change the number on the RHS to match the column that starts with the string "bD", or do you want to change the name of the variable on the LHS?

RichardJ
19-Tanzanite
I think a variable name - String would be a good function as it would allow variable names to be passed to results tables without having to use the double parenthesis.

OK. We are (i.e. I am) getting confused here. There are two requests: variable name to string, and string to variable name (i.e. create a variable based on a string). You want variable name to string. I see the utility of that. Wayne asked for string to variable name, and that's the one where I don't see how it would be used in practice.

MikeArmstrong
5-Regular Member

OK. We are (i.e. I am) getting confused here. There are two requests: variable name to string, and string to variable name (i.e. create a variable based on a string). You want variable name to string. I see the utility of that. Wayne asked for string to variable name, and that's the one where I don't see how it would be used in practice.

Oh right.

The function I requested wouldn't be top of my most wanted functions, but would defiantly be included in an ideal world.

The string to variable function might be useful if data is being brough in to Mathcad. If reactions had been calculated for a pin joint system and they where brought is a string. I haven't had this problem myself, but can see where it might be needed.

Mike

AlanStevens
16-Pearl

Richard Jackson wrote:

. Wayne asked for string to variable name, and that's the one where I don't see how it would be used in practice.

Suppose you import an Excel file that has, say a whole load of variable names/descriptors in one column and the corresponding numerical values in the adjacent column. Then it might be useful to keep the same names in Mathcad, and, instead of rewriting them it could be useful simply to write something like

str2var(data<0>,data<1>) or str2var(data<0>):=data<1> (where I've assumed the relevant Excel information has been read into the first two columns of Mathcad variable, data.

Alan

RichardJ
19-Tanzanite

str2var(data<0>):=data<1>

But unless you know what the string in data<0> will be when you write the worksheet the variable will not be used for anything, because it's not referenced anywhere in the worksheet. And if you do know what the string in data<0> will be, say MyVar, then you could just write MyVar:=data<1> when you create the worksheet.

StuartBruff
23-Emerald II

Richard Jackson wrote:

I think a variable name - String would be a good function as it would allow variable names to be passed to results tables without having to use the double parenthesis.

OK. We are (i.e. I am) getting confused here. There are two requests: variable name to string, and string to variable name (i.e. create a variable based on a string). You want variable name to string. I see the utility of that. Wayne asked for string to variable name, and that's the one where I don't see how it would be used in practice.

It's on my 2007 old list. I have wanted the capability on several occasions to create a family of variables and/or function without having to type them in manually. I kind of envisaged it be a 'lhs of a definition' function that created the variable and assigned the rhs to the variable, with the variable itself then existing from that point onwards.

It has occasionally struck me that one possible way to improve the utility of the Mathcad interface is to employ some common CAD features and give the user the capability to build multiple regions, particularly when laying out plots - I've often wished I could put, say, an 'array' of plots to handle different cases rather than have a single, confusing plot with multiple lines that cross or overlap.

Stuart

... this feels like deja vu all over again ... you're not attempting to fill Jean's ecological role are you? click, click, click ... type, type, type ... click, click, click

RichardJ
19-Tanzanite
It's on my 2007 old list. I have wanted the capability on several occasions to create a family of variables and/or function without having to type them in manually.

OK. Laziness is a legitimate justification for anything.

... this feels like deja vu all over again ... you're not attempting to fill Jean's ecological role are you? click, click, click ... type, type, type ... click, click, click

There is a big difference. I am not stating, despite overwhelming evidence to the contrary, that there is no use for sunch a capability. I am genuiinely trying to understand what it would be used for,

MikeArmstrong
5-Regular Member

I get Wayne's point now. Maybe something like below.

Clipboard01.jpg

Mike

RichardJ
19-Tanzanite

But you would have to know that the variable names would be string1, string2, etc, or you couldn't use them for anything later in the worksheet. So you could just write:

strings.gif

Granted, that is more typing (Stuart's argument), but unless the number of variables is really large that doesn;t make too much difference.

wayne
2-Guest

Richard,

In my case, I set up the calculations in the worksheet based on the location of a vector of data in a matrix (LCmat)

But the order of the vectors may change and the type of data may change also, for different jobs (and different useres), and the names (bM, for mechanical) are not predetermined, so I cant just search for known strings strings and assign variables that way.

So if I could use the heading as a variable, then I do not need to know before hand the names and location of the vectors.

Right now, I must do this by hand for each job or even within a job if LCmat were changed. For example load type "bD" is a column heading, so I type bD=column location. Then when using bD data type, I can use bD as an index

But, this is error prone, especially given that there are diffferent users, and a user may even have several different jobs at the same time with different LCmat's. Also note that ther are 16 columns, and may be more, so it could easily happen the user may miss the correct assignment. What I am doiing will be used for production, so more precaution is necessary.

Thus, I would like to take a string and change it to a variable.

Wayne

RichardJ
19-Tanzanite

So are you saying that when you create the assignment for bD using str2var the rest of the worksheet has not been written? Then you write the rest of it, using bD as the variable name?

Your talk about "users" and "production" would imply that's not the case. But if the rest of the worksheet has already been written you can't just chnage the variable names, because then the rest of the worksheet will fail. If I have

Bd:=0.1

Answer:=sin(Bd)

I can't just chnage the assignment to a new variable name. I would have to go through the entire worksheet and also change every expression that depended on it.