By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,641 Members | 1,446 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,641 IT Pros & Developers. It's quick & easy.

Scope, Variables

P: n/a
Visual Studio Code Editor
I get a '...not declared' syntax error after the initial variable
declaration in any other subs or functions. Dim has module level scope so
any subs or functions in the class should recognize iAnything. Why the
syntax errors?
For example:

Class aclass...
Private Sub blabla
dim iAnything as Integer
iAnything = 5 'ok
End Sub

Private Sub AnotherSub
Dim oSomething as Integer
oSomething = iAnything 'syntax error - iAnything not declared
End Sub

Function Afn(ByVal...)As Atype
Dim oSomething as Integer
oSomething = iAnything 'syntax error - iAnything not declared
End Function
End Class
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
* "Dennis D." <te**@dennisys.com> scripsit:
Visual Studio Code Editor
I get a '...not declared' syntax error after the initial variable
declaration in any other subs or functions. Dim has module level scope so
any subs or functions in the class should recognize iAnything. Why the
syntax errors?


Declare 'iAnything' /outside/ a method/property.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #2

P: n/a
Thank You.

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2o************@uni-berlin.de...
* "Dennis D." <te**@dennisys.com> scripsit:
Visual Studio Code Editor
I get a '...not declared' syntax error after the initial variable
declaration in any other subs or functions. Dim has module level scope so any subs or functions in the class should recognize iAnything. Why the
syntax errors?


Declare 'iAnything' /outside/ a method/property.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

P: n/a
remember - wherever you declare the variable is where it lives
declare it in a sub - and you cannot use it outside the sub - except for
passing as args.

"Dennis D." <te**@dennisys.com> wrote in message
news:uk*************@TK2MSFTNGP09.phx.gbl...
Visual Studio Code Editor
I get a '...not declared' syntax error after the initial variable
declaration in any other subs or functions. Dim has module level scope so
any subs or functions in the class should recognize iAnything. Why the
syntax errors?
For example:

Class aclass...
Private Sub blabla
dim iAnything as Integer
iAnything = 5 'ok
End Sub

Private Sub AnotherSub
Dim oSomething as Integer
oSomething = iAnything 'syntax error - iAnything not declared
End Sub

Function Afn(ByVal...)As Atype
Dim oSomething as Integer
oSomething = iAnything 'syntax error - iAnything not declared
End Function
End Class

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Nov 21 '05 #4

P: n/a
I suppose you also know that any variable declared inside a For...Next loop
or If...end if block only has scope within the blocks in which it was
declared.

"Dennis D." wrote:
Visual Studio Code Editor
I get a '...not declared' syntax error after the initial variable
declaration in any other subs or functions. Dim has module level scope so
any subs or functions in the class should recognize iAnything. Why the
syntax errors?
For example:

Class aclass...
Private Sub blabla
dim iAnything as Integer
iAnything = 5 'ok
End Sub

Private Sub AnotherSub
Dim oSomething as Integer
oSomething = iAnything 'syntax error - iAnything not declared
End Sub

Function Afn(ByVal...)As Atype
Dim oSomething as Integer
oSomething = iAnything 'syntax error - iAnything not declared
End Function
End Class

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.