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
Code Explorer Variables not listing
Moderators: David Barker, Jerry Messina
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.
Code Explorer Variables not listing
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
Bryan