Page 1 of 2

Show constant as constant name in Variable Viewer

Posted: Sat Sep 14, 2013 8:15 am
by Korolev Michael

Code: Select all

#Success = 45
var = #Success
It would be groovy, if Variable Viewer will display var as "#Success" in addition to "45".
Can you incarnate this a VERY handy option? :)

Re: Show constant as constant name in debugger

Posted: Sat Sep 14, 2013 9:24 am
by Fred
Unfortunately, it's not possible as we don't know which constant you assigned to var. Many different constants can have the '45' value.

Re: Show constant as constant name in debugger

Posted: Sat Sep 14, 2013 9:38 am
by Korolev Michael
You can make possibility for assigning to variables a set of possible constants. And save these assigned values in pb file.
For example, in Variable Viewer, click to variable "var", then choose and bind defined constants #Success and #Failed to it.

Thus, Variable Viewer will always show #Success or #Failed instead of 45 or 47.

Re: Show constant as constant name in debugger

Posted: Sat Sep 14, 2013 9:51 am
by Fred
It won't work everytime and surely don't want the debugger display wrong info ;)

Re: Show constant as constant name in debugger

Posted: Sat Sep 14, 2013 10:59 am
by PB
What happens here? ;)

Code: Select all

#Success = 45
#Failure = 45
var = #Success
Debug var ; Does the IDE show #Success or #Failure ?

Re: Show constant as constant name in debugger

Posted: Sat Sep 14, 2013 11:15 am
by Korolev Michael
IDE will show "multiple constant matches found". This means, there is a mistake in code, because you bound two equally defined constants.

Does anyone assign two equal values for two constants, in real project? Constant values can coincide if they belongs to different abstraction layers/objects e.t.c.

Edit: I meant not Debugger, but Variable Viewer, sorry. Edited all my messages.

Re: Show constant as constant name in debugger

Posted: Sat Sep 14, 2013 11:41 am
by PB
> Does anyone assign two equal values for two constants, in real project?

Yes. In fact, it's totally normal.

Re: Show constant as constant name in Variable Viewer

Posted: Sat Sep 14, 2013 11:47 am
by Korolev Michael
No, I meant not two equal constant within all project. I mean two equal constants within one variable.

How one variable can have 45 = #Success OR #Failed at same time, can you explain me?

Re: Show constant as constant name in debugger

Posted: Sat Sep 14, 2013 11:48 am
by Little John
Korolev Michael wrote:This means, there is a mistake in code, because you bound two equally defined constants.
No, not at all.
Korolev Michael wrote:Does anyone assign two equal values for two constants, in real project?
:?:

Code: Select all

#NumberOfWives = 1
#NumberOfChildren = 1
Do you think there is a mistake in this code snippet, or in the life of the respective person?

Re: Show constant as constant name in Variable Viewer

Posted: Sat Sep 14, 2013 11:51 am
by Fred
You can imagine such (pseudo) code:

Code: Select all

Select GadgetType()
  Case #PB_GadgetType_Button
    Flags = #PB_Gadget_Toggle
  Case #PB_GadgetType_Tree
    Flags = #PB_Gadget_CheckBoxes
EndSelect
#PB_Gadget_CheckBoxes and #PB_Gadget_Toggle can have the same value in PB because it's not applied to the same gadget. Anyway, there is no reliable ways to revert a numeric value back to a constant at runtime.

Re: Show constant as constant name in Variable Viewer

Posted: Sat Sep 14, 2013 11:52 am
by PB
> How one variable can have 45 = #Success OR #Failed at same time

It doesn't. The var = 45. So, which 45 constant is it referring to? Nobody knows.

What you're asking is like asking where the water in a hose came from. The hose
is the variable name, and the water is the variable value. So where did the water
come from? Nobody knows.

Re: Show constant as constant name in Variable Viewer

Posted: Sat Sep 14, 2013 11:54 am
by Fred
PB wrote:What you're asking is like asking where the water in a hose came from. The hose
is the variable name, and the water is the variable value. So where did the water
come from? Nobody knows.
Another similar quote I read somewhere was the following: "It's like trying to get back eggs and flour from a backed cake" :)

Re: Show constant as constant name in Variable Viewer

Posted: Sat Sep 14, 2013 11:58 am
by PB
I think this is what the OP wants:

Code: Select all

#alone=1
#one=1
#single=1

var=#one
Debug var ; Shows "#one" instead of "1"
But it just doesn't work like that. var has become 1, but the
debugger doesn't know if it's from #alone, #one or #single.
And for all practical purposes, it doesn't even matter.

Re: Show constant as constant name in Variable Viewer

Posted: Sat Sep 14, 2013 1:08 pm
by Korolev Michael
I know what you are talkin' about, guys. Are you sure that you really got the question?

@PB, I proposed to do something like "binding" variables or "tracking".

Example one
1. In Variable Viewer (VV), click by right button on var, choose "Bind Constants"
2. Window pops up, you type there:

Code: Select all

#one;
And save. OK, VV knows chosen constants for tracking.

When you run:
Image

We got #one, because we bound with var only #one!

Another example.
1. In Variable Viewer (VV), click by right button on var, choose "Bind Constants"
2. Window pops up, you type there:

Code: Select all

#one;
#two
Save.

Run and you'll get:
Image

VV shows #one, step in, then shows #two, because we bound them both!

Yet another example.
1. In Variable Viewer (VV), click by right button on var, choose "Bind Constants"
2. Window pops up, you type there:

Code: Select all

#one;
#alone
Run:
Image

We got this exception because there are too many bound constants that equals to 1.

Bottom line:
Why did I propose this? You got status 4578. What does it mean, do you remember? Sometimes, with raw value of variable we can't say, what really this value means. Especially, when we operating with constants only, not with numbers.

This can be done. We just need to add some additional info for Variable Viewer. Info, what constants it need to track for particular variable. Whew.

I already know, no one supports this request, but I'll try to pose my point, at least.

Re: Show constant as constant name in Variable Viewer

Posted: Sat Sep 14, 2013 2:11 pm
by PB
> You got status 4578. What does it mean, do you remember?

Well, you shouldn't be checking for what 4578 is; you should always
be checking instead for a constant of that value. Like the following:

Code: Select all

#status_ok=1
#status_wrongname=2
#status_filenotfound=4578

[...]

result = CheckSomething()

If result = #status_filenotfound
  MessageRequester("Error","File not found!")
EndIf
Doing this means you never have to remember what 4578 means.