Name "XXX" is not declared.

aybe

New member
Joined
Aug 27, 2005
Messages
1
Programming Experience
Beginner
hi,


say on VS2005,VB,

- i have defined a datatable on sub 1

- when i try to use datatable from sub 2,
i have the following error : "Name 'dt' is not declared."

i tried to change from private to public (or shared) sub , but it gives no results.

how can i make it visible for both subs without redefining it, thus erasing populated data ?


also

i already found i have to use "private" sometimes instead of "dim"

however can you tell what is the use of "private sub" and "public sub" ?



thank you


Aybe
 
Declare your datatable on the top of the page using dim dt as datatable and then populate it in sub 1. now when u reuse this dt in sub 2 it will give you the desired results.
 
What nakracreative describes is the scope of the variable.
If you declare the variable within a procedure, then the variable only has procedural scope meaning that the variable only exisits for the lifetime of the procedure. If you declare a variable in a class, then it has class scope which means it exists for the lifetime of the class.
Declaring a Sub as Private versus Public will affect it's scope. What this means: If you declare a Sub as Private, you can only use that procedure in the class that it is contained in. If declared as Public, the procedure can be utilized outside of that class, if an instance of that class has been created. A Shared Public procedure needs not an instance of the class to be used (for instance, all of the System.IO.Directory's methods are Public Shared which means that you don't need an instance of the System.IO.Directory class in order to use it's methods).
You may also want to look at the Friend scope as it is best to use as narrow a scope as possible.
 
Back
Top