Code Explorer Variables not listing

Discuss the Integrated Development Environment (IDE)

Moderators: David Barker, Jerry Messina

Post Reply
Bryan
Registered User
Registered User
Posts: 18
Joined: Tue Feb 19, 2008 6:50 am
Location: Nelson, B.C. Canada

Code Explorer Variables not listing

Post by Bryan » Sun Feb 01, 2009 3:07 am

In my programming to date I've made a practice of declaring all my variables at the beginning of a program or module and they've always showed up in the Code Explorer tree under "Variables". I'm still learning to program in Swordfish (and loving it!) so I'm always looking at what others have done, lots of different styles out there. I've recently noticed that several programmers declare variables at the beginning of their subroutines - I thought I'd give that a try thinking it would make reading and maintaining the program a little easier. What I found was that if I did that, these variables did not show up in the Code Explorer tree. I thought I must be doing something wrong so I copied and imported other's programs into the IDE - same story. Then I tried a very simple experiment:

Dim test As Byte

Sub testsub()
Dim newvariable As Byte
End Sub

"newvariable" didn't show up in the Explorer Tree but "test" did!

Is this a limitation of the Code Explorer? Do all the variables need to be declared at the beginning of the program if you want them to show up on the explorer tree?

Bryan

User avatar
Steven
BETA Tester
Posts: 406
Joined: Tue Oct 03, 2006 8:32 pm
Location: Cumbria, UK

Post by Steven » Sun Feb 01, 2009 10:02 am

There is a fundamental difference between variables declared at the start of the code and those declared within subroutines/functions. Those at the beginning are global - they are accessible by all code within a module or program, and outside of a module also if they are made public. Variables declared within a subroutine are only visible within a subroutine and are destroyed after a subroutine has exited - these are referred to as local variables. The code explorer is just showing global variables. Hope this helps.

Bryan
Registered User
Registered User
Posts: 18
Joined: Tue Feb 19, 2008 6:50 am
Location: Nelson, B.C. Canada

Code Explorer Variables not listing

Post by Bryan » Tue Feb 03, 2009 6:46 am

Hi Steven, thanks for clearing this up for me. I put "Public" in front of my "newvariable" and sure enough it showed up in the variable list on the explorer tree. Lots more to learn but really enjoying the journey !

Bryan

Post Reply