how to get a list of used variables ?

Just starting out? Need help? Post your questions and find answers here.
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

how to get a list of used variables ?

Post by wimapon »

How can i get a list of used variables in a program.
once i did it.. but now.... do not know
Wim
User avatar
RichAlgeni
Addict
Addict
Posts: 935
Joined: Wed Sep 22, 2010 1:50 am
Location: Bradenton, FL

Re: how to get a list of used variables ?

Post by RichAlgeni »

It's easy. What you do is you print out your program on paper. Then you go through each line, whenever you see a variable, write it down on another piece of paper. Voila! You have a list of variables!

Now, if you need a sorted list, you need to get 26 more pieces of paper. Go through your list, write all variables that start with 'A' on the first paper, 'B' on the second, and so on. Leave room above and below so you can add the variables in the correct order. When done, you will have a sorted list of variables!
User avatar
JHPJHP
Addict
Addict
Posts: 2252
Joined: Sat Oct 09, 2010 3:47 am

Re: how to get a list of used variables ?

Post by JHPJHP »

In the menu of the IDE: tools/Variable Viewer

If you're not investing in yourself, you're falling behind.

My PureBasic StuffFREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: how to get a list of used variables ?

Post by IdeasVacuum »

It's always a good idea to have EnableExplicit at the top of your code - the compiler will then let you know if any variable present is not declared.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: how to get a list of used variables ?

Post by Tenaja »

IdeasVacuum wrote:It's always a good idea to have EnableExplicit at the top of your code - the compiler will then let you know if any variable present is not declared.
Is there a way to get the opposite of that--which vars are declared but not used?
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: how to get a list of used variables ?

Post by luis »

Tenaja wrote: Is there a way to get the opposite of that--which vars are declared but not used?
No, would be very useful and it has been requested. It's something the compiler should be able to track with little effort.
But if you don't want to wait hoping it will be implemented maybe now thanks to the /PREPROCESS switch it is something that could be written as an IDE tool.

I'm convinced there are tons of unused variables in current PB sources. :)
"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: how to get a list of used variables ?

Post by skywalk »

Yes, the /PREPROCESS switch enables many new opportunities but the line numbers will be tricky when referring back to multiple source files.
I am also guilty of stray variables.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: how to get a list of used variables ?

Post by wimapon »

sorry, was a few days away.

My problem in large programs is always, how can i see that a new to choose variable
is not already used, while programming.
It is very dangerous to use a variable for something else....

So it would be very smart to have a tool to get all the used variables in your program.

I use other compilers. they have a way to get a list of all used variables..
so why does pb not have it.....

if it does not exist, i have to make it myself.....

for example: hour, uur, hours, newhour, oldhour, hours2, hours3, hour_yesterday etc.
sometime i do use more than 10 hour names in a large program....



I will try to use: ( maybe it helps)
EnableExplicit
Define a.d
but i am afraid that i have to read too much variables before i can define a new one...




Maybe the best way is to go to the top of your program and than with the editor
find/replace to have a look.....

Wim
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: how to get a list of used variables ?

Post by wilbert »

Did you overlook the answer from JHPJHP ?
http://www.purebasic.fr/english/viewtop ... 05#p452405
The "Variable Viewer" seems like the easiest way to me.
Windows (x64)
Raspberry Pi OS (Arm64)
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: how to get a list of used variables ?

Post by wimapon »

Yes i did overlook.. sorry sorry.

But i do remember that i tried it once and decided "this is nog good anough".
but now i do not remember why.

so i will start to use the variable viewer again.

thank you all for your help

Wim
Gadget
User
User
Posts: 39
Joined: Tue Mar 11, 2014 8:11 pm
Location: UK

Re: how to get a list of used variables ?

Post by Gadget »

Hi,

I tried using the Tools ... Variable Viewer option and had a couple of problems ...

1. Protected variables within a procedure are not listed. According to the PB manual (below) these should be listed.

2. The manual says that it the option can be configured in the preferences. However, I could find this in preferences.

Am I missing the obvious again ?

PB Manual says:
The variable viewer can display variables , Arrays , lists , Constants , Structures and Interfaces defined in your source code, or any currently opened file. You can configure what exactly it should display in the preferences .
Note: The displaying of variables is somewhat limited for now. It can only detect variables explicitly declared with Define , Global , Shared , Protected or Static .
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: how to get a list of used variables ?

Post by IdeasVacuum »

I will try to use: ( maybe it helps)
EnableExplicit
Define a.d
but i am afraid that i have to read too much variables before i can define a new one...
If you try to define a variable name that is already used the compiler will alert you when you run the code. With EnableExplicit(), un-defined variables trigger an alert.

If you want to create a new var but think you may have already used the var name, use Find to see if it exists - that is better than looking at a list of vars, you could still miss it :)
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: how to get a list of used variables ?

Post by luis »

Gadget wrote: 1. Protected variables within a procedure are not listed. According to the PB manual (below) these should be listed.
I never use this so I've just looked into it. You are right.

Looks like a bug:

Code: Select all

Global var

Procedure a()
 Protected a, b, c
EndProcedure
Only "var" is listed.

Change Protected to Global and "a, b, c" are also listed. Also work with Shared. Not with Protected or Static or Define.

Seems so gigantic I find strange nobody noticed before unless is new... or no one is using it maybe ?
"Have you tried turning it off and on again ?"
A little PureBasic review
Thade
Enthusiast
Enthusiast
Posts: 266
Joined: Sun Aug 03, 2003 12:06 am
Location: Austria

Re: how to get a list of used variables ?

Post by Thade »

luis wrote:
Gadget wrote: Seems so gigantic I find strange nobody noticed before unless is new... or no one is using it maybe ?
I use it and for my needs its exactly as it should be.
I can define 100 times vars i or j or k in 100s of Procedures and they all have nothing to do with the main program.
The variable viewer shall show only variables which are relevant.

If there would be an option to show variables used in each procedure ... that would be another story ... lists for each procedure must then be displayed ... or maybe the variable viewer would have to check if the cursor is located inside a Procedure and display only those variables inside that procedure.

@EnableExlicit propagandists
There are some EnableExplicit Fans here ... I cannot share that enthusiasm ... coding that way leaves BASIC in my view. And with that great IDE with best autocomplete it is not needed at all.
I only type a variable once ... all times later I need that var or array or structure or whatever I get it from the autocomplete drop down window which opens when I type in the first letters.
So it always will be correct and not mis-spelled ... and making logic mistakes will not be covered by EnableExplicit anyway.
Who wants to use EnableExplicit and codes that way, its okay ... but don't give other poeple the feeling they are idiots if they don't, each time they read your posts.
This is something like the political correctness or climate change debate ... keep your vision, but don't spoil other peoples life ... 8)
--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: how to get a list of used variables ?

Post by luis »

Thade wrote: I use it and for my needs its exactly as it should be.
Problem is it doesn't do what's documented.
help wrote:It can only detect variables explicitly declared with Define, Global, Shared, Protected or Static
Thade wrote: I can define 100 times vars i or j or k in 100s of Procedures
I agree and that's one of the reasons why I don't find it much useful as it is (if it were working as documented, I mean).
Thade wrote: @EnableExlicit propagandists
I'm a supporter (I find it essential) more than a propagandist (I don't care if you don't use it as long you don't post bogus code as a consequence).
Can I read it anyway ? I'm reading.
Thade wrote: Who wants to use EnableExplicit and codes that way, its okay ... but don't give other poeple the feeling they are idiots if they don't, each time they read your posts.
I wouldn't feel like an idiot even if you were explicitly (duh) posting that using GOTO is for idiots just because you think so.

Anyway, I don't recall people calling other idiots on the ground of EnableExplicit, but maybe I have missed it.
If I didn't probably you are reading too much in some other kind of remark. But why you should feel like an idiot ?

If it works well for you that's all that count as long I'm not forced to do the same.

There is a but: reality suggests many people not using EnableExplicit post code with the kind of errors (mistyped variables) you don't make.
Not only mistyped variables, but sometimes the implicit order in their declaration causes correctly typed variables to not have the intended scope (a programmer error, but nevertheless...).
In the many cases we (or at least I) have witnessed in the forum, EnableExplicit would have helped them in creating less bugged code.
So when I see someone suggesting to use it, or when I suggest to use it, usually the reason is the code one post above contains errors EnableExplicit would have prevented.
In that case I find it a very good suggestion. I hope you are not against it.
The alternative would be to just suggest: "pay more attention next time". Not nearly as useful.
It's like suggesting to use the purifier when you see an error it would have caught.
"Have you tried turning it off and on again ?"
A little PureBasic review
Post Reply