|
-
Apr 17th, 2007, 11:54 PM
#1
Thread Starter
Member
[RESOLVED] [2005] Can variables in private sub be used outside ??
Hey guys!
I have a program in which i hav declared a few variables inside a 'Private Sub button_click'. I need to reuse the same variables in another Private Sub Button_Click.. Do i need to declare the same variables again in the second sub or can i continue to use it after i have i declared it in the previous sub.
Or do i declare the variables outside the subs and then use it in all the subs.
please advise
cheers
Abhilash
-
Apr 18th, 2007, 12:01 AM
#2
Re: [2005] Can variables in private sub be used outside ??
It depends on if you need same Variables (which means the same data) in multiple subs. You can declare them at a Module level and use them in the methods in that module.
Use [code] source code here[/code] tags when you post source code.
My Articles
-
Apr 18th, 2007, 12:09 AM
#3
Re: [2005] Can variables in private sub be used outside ??
Local variables are not accessible outside the block in which they are declared. If you declare a variable inside a method then outside that method that variable simply doesn't exist. You can declare another variable in another method with the same name but those two variables are not related in any way whatsoever. If you need a variable to be accessible from two independent blocks then the variable must be declared outside both of them. If those blocks are methods then the variable must be declared at the class-level or equivalent.
Note that by "block" I mean any section of code that starts at one line and ends at a corresponding End statement or the like, like Function...End Function, If...End If, For...Next, etc.
-
Apr 18th, 2007, 12:47 AM
#4
Thread Starter
Member
Re: [2005] Can variables in private sub be used outside ??
Thx guys.. i got the point
cheers
Abhilash
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|