473,382 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Scope, Variables

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
4 1073
* "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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Hal Vaughan | last post by:
Being self taught, this is one thing I've always had trouble with -- I finally get it straight in one situation and I find I'm not sure about another. I have a class that keeps calling an...
33
by: Arthur | last post by:
>>>a= >>> for p in a: print p 1 2 3 >>> p 3 My naive expectation was that p would be 'not defined' from outside
3
by: Anonymous | last post by:
Is namespace the same thing as scope? While reading the book "Thinking in C++", I was under the impression that namespace is, well, a namespace--a feature to create a hiearchy for identifiers...
6
by: pembed2003 | last post by:
Hi all, I am reading the book "C++ How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
3
by: Grant Wagner | last post by:
Given the following working code: function attributes() { var attr1 = arguments || '_'; var attr2 = arguments || '_'; return ( function (el1, el2) { var value1 = el1 + el1; var value2 = el2...
5
by: pembed2003 | last post by:
Hi all, I am reading the book "C How to Program" and in the chapter where it discuss scope rule, it says there are four scopes for a variable: function scope file scope block scope...
7
by: WXS | last post by:
Vote for this idea if you like it here: http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=5fee280d-085e-4fe2-af35-254fbbe96ee9...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
0
MMcCarthy
by: MMcCarthy | last post by:
We often get questions on this site that refer to the scope of variables and where and how they are declared. This tutorial is intended to cover the basics of variable scope in VBA for MS Access. For...
5
by: chromis | last post by:
Hi there, I've recently been updating a site to use locking on application level variables, and I am trying to use a commonly used method which copies the application struct into the request...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.