×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Contact US

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.

Students Click Here

Is there an easy way to tell if a variable or function has been defined.

Is there an easy way to tell if a variable or function has been defined.

Is there an easy way to tell if a variable or function has been defined.

(OP)
I am a long time Mathcad and C programmer. In C one includes header files. Since many header files are often included, it is possible that a variable or function has been defined before so there is a test to see if the variable has been defined before, so it doesn't get redefined.

In Mathcad I often use the ability to include other mathcad files. What I need is a way to test if a variable has been defined before so it is not redefined
In short, Mathcad has no
#ifdef
#endif
feature like C or C++ have that I can see.
I have been using Mathcad since Mathcad 3 or about 30 years.
I am shocked that I haven't noticed this before.
I have about 1000+ Mathcad files and was starting to "clean them up" when I came across this problem. So many have Bode plots with common code or Pole Zero plots that are the same with only the variables being different.



Peter Nachtwey
Delta Computer Systems
http://www.deltamotion.com
http://forum.deltamotion.com/
IFPS Hall of Fame Member

RE: Is there an easy way to tell if a variable or function has been defined.

I don't think there's anything obvious. Mathcad's programming has always gotten short-sheeted. Mathcad as a whole obviously knows when "x" is undefined, but there's no utility function for that.

TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

RE: Is there an easy way to tell if a variable or function has been defined.

I've started to explicitly list dependencies in my octave scripts (badly) so I don't run into this. In Mathcad are variables global by default?

Cheers

Greg Locock


New here? Try reading these, they might help FAQ731-376: Eng-Tips.com Forum Policies http://eng-tips.com/market.cfm?

RE: Is there an easy way to tell if a variable or function has been defined.

Quote:

In Mathcad are variables global by default?

Insofar as most variables are defined on the main worksheet; functions and programs have locally scoped variables, but can use global variables.

Global variables in sheets that are referenced become global variables of the referencing sheet, hence the need for a way to check if the variable defined on a referenced sheet.

TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

RE: Is there an easy way to tell if a variable or function has been defined.

In SMath, I can use a variable name and instead of using := to describe the function, I can use =. If the value has not been defined, the program automatically assigns :=, I don't know if MathCAD does that.

-----*****-----
So strange to see the singularity approaching while the entire planet is rapidly turning into a hellscape. -John Coates

-Dik

RE: Is there an easy way to tell if a variable or function has been defined.

Yes, Mathcad does that too.

RE: Is there an easy way to tell if a variable or function has been defined.

Dik, the issue, I think, is that operation only works in real-time, i.e., you pick a spot on the sheet and type that in, but that doesn't work if you have an existing sheet and then add a referenced sheet to the start of the existing sheet. And variable already defined in the referenced sheet will simply get redefined in place, and any calls to functions created in the referenced sheet using that variable would use the new definition instead of the original definition.

TTFN (ta ta for now)
I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg
FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

RE: Is there an easy way to tell if a variable or function has been defined.

In a collpased area above each calculation group I zero out all variables being used in the section below using := if the section is intended to be local only. If I am going to use the calculation as a block or reference or insert I might include a collapsed area below the calculation to zero out local variables and/or show calculated results. If a section needs to carry or show values defined above then I include a collapsed area above and/or below with each of those using =

In essence I'm using programming technique I was taught in college - be sure to initialize before and clean up after blocks of code.

During the checking process I can open each collapsed area and see if the values make sense.

RE: Is there an easy way to tell if a variable or function has been defined.

(OP)
:(
The problem is that I must always manually define or undefine variables in the included/inner/child work sheet. I think the only solution is to NEVER define the variables in the included worksheet but have a test outer worksheet that defines varuables for testing the inner worksheet.
This way the inner worksheet never defines variables that override the outer worksheet's variables.
I just thought I would post my kludge solution. Frustrating.
For all its flaws. I still like using Mathcad for making YouTube videos. I have the whole worksheet tested and blow it up to 150% to 200% for the video. This way I don't waste time crating things on video like the professors do. This wastes time. The Mathcad worksheet is used as an outline too.


Peter Nachtwey
Delta Computer Systems
http://www.deltamotion.com
http://forum.deltamotion.com/
IFPS Hall of Fame Member

RE: Is there an easy way to tell if a variable or function has been defined.

IRS... if an existing sheet, then by using the '=' operator will show a value and you can then move this value upwards until it 'blanks out'... and that is the location of where the value was defined.

-----*****-----
So strange to see the singularity approaching while the entire planet is rapidly turning into a hellscape. -John Coates

-Dik

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! Already a Member? Login


Resources

Low-Volume Rapid Injection Molding With 3D Printed Molds
Learn methods and guidelines for using stereolithography (SLA) 3D printed molds in the injection molding process to lower costs and lead time. Discover how this hybrid manufacturing process enables on-demand mold fabrication to quickly produce small batches of thermoplastic parts. Download Now
Design for Additive Manufacturing (DfAM)
Examine how the principles of DfAM upend many of the long-standing rules around manufacturability - allowing engineers and designers to place a part’s function at the center of their design considerations. Download Now
Taking Control of Engineering Documents
This ebook covers tips for creating and managing workflows, security best practices and protection of intellectual property, Cloud vs. on-premise software solutions, CAD file management, compliance, and more. Download Now

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