Seeing the value of a variable

Hi,

I wanted to know if there is a command to see the variable value on the command prompt window? I know I can write a command in the procedure file, and then run the program to see the variable value. But I believe there should be a quick way to check the value of any variable.

 

Thanks

Would you provide a MWE (minimum working example) of the procedure and denote where you need something special to happen.

In reply to by pratapv397

It sounds like the debugger would be useful.

From the procedure window, select Procedure - Enable Debugger, then right click in procedure to set a break point, then run procedure. The debugger will show you the value of a variable (and much more) as you step through your procedure.

displayHelpTopic "the debugger"

 

In reply to by tony

Also, if you are referring to a global variable, you could see its current value using the Data Browser.  Open the Data Browser, navigate to the folder containing the variable and select the variable.  Its value will be shown in the info box at the bottom of the Browser window.  If the info box isn't displayed, select the "info" checkbox on the left side of the Browser.

In reply to by jjweimer

Here is a very short example: 

Lets assume we have this command in the procedure file:

variable d= Binarysearch(timewave, valve_stop_time)

I ran the procedure, and so, there'll be a value for variable d. Since, I didn't print it, I don't know the value of d. However, while looking at the results, I want to know the value of 'd'. Is it possible to find the value without re-running the procedure?

If you are running a user-defined function, "Variable d" creates a local variable that ceases to exist when the function ends. Execute this for details:

DisplayHelpTopic "Local Versus Global Variables"

If you have not already done it, or if you need a refresher, I recommend reading the entire "Programming" help file.

I'll probably change the variables to global variables.

A few suggestions taken from my experience might help to make your future coding efforts happier.

  • Do NOT change to global variables just for the reason to be able to see a numerical value as a function runs. Use the debugger for this.
  • Do NOT change to global variables just for the reason to get a written record of the value when a function runs. Use the print function for this (print to history or print to a notebook). Alternatively, create a control panel with a value display and post the value to the control panel.
  • Do use global variables as one method to pass values from one function to another function (but do so sparingly).
  • Do use global variables as one option to store "permanent" values (e.g. startup values) for a procedure.

I mostly agree, Jeff. But for the third item I would say there is almost no reason to use globals to pass values from one function to another. The main reason for global variables is to hold a value that needs to persist between function runs, like a preference setting, or some sort of history such as holding the last-used value to use it as a default for the next run.

Global variables make it difficult to trace where a given value comes from- it might be set by code a long way from the code where a bug crops up, or it might be left over from a previous invocation.

Passing values as input parameters to functions can be inconvenient at times (I'm thinking of the case where a value starts at the top level and needs to be passed down a long chain of function invocations) but the call chain gives you a traceable link back to where the value came from.

A long way to say, Pratap397, that you should get used to using function input parameters.

Or maybe you should post some code (a little bit of code that illustrates a problem) and we can show you how we would do it. Best to develop good practices now before you get too deep in!

I mostly agree, Jeff. But for the third item I would say there is almost no reason to use globals to pass values from one function to another.

Always glad to hear your perspective. I'm still shaking some old school habits myself, and (mis)-using global variables is one of them.

Or maybe you should post some code (a little bit of code that illustrates a problem) ...

As I'm learning on another forum, posting a MWE (minimum working example) is always good practice.