Seeing the value of a variable
pratapv397
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
print?
print myvar
October 26, 2018 at 09:47 am - Permalink
In reply to print? Variable myvar = 5… by johnweeks
I am actually running a procedure which has a variable. How to quickly see that variable in the command prompt?
October 26, 2018 at 10:17 am - Permalink
Would you provide a MWE (minimum working example) of the procedure and denote where you need something special to happen.
October 26, 2018 at 11:04 am - Permalink
In reply to I am actually running a… 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"
October 26, 2018 at 11:19 am - Permalink
In reply to It sounds like the debugger… 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.
October 26, 2018 at 12:09 pm - Permalink
In reply to Would you provide a MWE … 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?
October 26, 2018 at 12:10 pm - Permalink
DisplayHelpTopic "The Debugger"
October 26, 2018 at 12:28 pm - Permalink
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:
If you have not already done it, or if you need a refresher, I recommend reading the entire "Programming" help file.
October 26, 2018 at 01:19 pm - Permalink
In reply to If you are running a user… by hrodstein
Thank you all for your help. I think I got the idea. I'll probably change the variables to global variables.
October 26, 2018 at 02:13 pm - Permalink
A few suggestions taken from my experience might help to make your future coding efforts happier.
October 26, 2018 at 03:04 pm - Permalink
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!
October 26, 2018 at 03:44 pm - Permalink
Always glad to hear your perspective. I'm still shaking some old school habits myself, and (mis)-using global variables is one of them.
As I'm learning on another forum, posting a MWE (minimum working example) is always good practice.
October 26, 2018 at 06:26 pm - Permalink