how to get a list of used variables ?
-
- Enthusiast
- Posts: 290
- Joined: Thu Dec 16, 2010 2:05 pm
- Location: Delfzijl ( The Netherlands )
- Contact:
how to get a list of used variables ?
How can i get a list of used variables in a program.
once i did it.. but now.... do not know
Wim
once i did it.. but now.... do not know
Wim
- RichAlgeni
- Addict
- Posts: 935
- Joined: Wed Sep 22, 2010 1:50 am
- Location: Bradenton, FL
Re: how to get a list of used variables ?
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!
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!
Re: how to get a list of used variables ?
In the menu of the IDE: tools/Variable Viewer
If you're not investing in yourself, you're falling behind.
My PureBasic Stuff ➤ FREE STUFF, Scripts & Programs.
My PureBasic Forum ➤ Questions, Requests & Comments.
-
- 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 ?
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.
If it sounds simple, you have not grasped the complexity.
Re: how to get a list of used variables ?
Is there a way to get the opposite of that--which vars are declared but not used?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.
Re: how to get a list of used variables ?
No, would be very useful and it has been requested. It's something the compiler should be able to track with little effort.Tenaja wrote: Is there a way to get the opposite of that--which vars are declared but not used?
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
A little PureBasic review
Re: how to get a list of used variables ?
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.
I am also guilty of stray variables.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
-
- 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 ?
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
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
Re: how to get a list of used variables ?
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.
http://www.purebasic.fr/english/viewtop ... 05#p452405
The "Variable Viewer" seems like the easiest way to me.
Windows (x64)
Raspberry Pi OS (Arm64)
Raspberry Pi OS (Arm64)
-
- 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 ?
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
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
Re: how to get a list of used variables ?
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 .
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 .
-
- 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 ?
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.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 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.
If it sounds simple, you have not grasped the complexity.
Re: how to get a list of used variables ?
I never use this so I've just looked into it. You are right.Gadget wrote: 1. Protected variables within a procedure are not listed. According to the PB manual (below) these should be listed.
Looks like a bug:
Code: Select all
Global var
Procedure a()
Protected a, b, c
EndProcedure
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
A little PureBasic review
Re: how to get a list of used variables ?
I use it and for my needs its exactly as it should be.luis wrote:Gadget wrote: Seems so gigantic I find strange nobody noticed before unless is new... or no one is using it maybe ?
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 ...

--------------
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
Yes, its an Irish Wolfhound.
Height: 107 cm; Weight: 88 kg
Re: how to get a list of used variables ?
Problem is it doesn't do what's documented.Thade wrote: I use it and for my needs its exactly as it should be.
help wrote:It can only detect variables explicitly declared with Define, Global, Shared, Protected or Static
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: I can define 100 times vars i or j or k in 100s of Procedures
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).Thade wrote: @EnableExlicit propagandists
Can I read it anyway ? I'm reading.
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.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.
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
A little PureBasic review