473,378 Members | 1,489 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,378 software developers and data experts.

variable scope problem

hi all,

If I have a variable declared outside the page_load sub and all other subs
on my page, and I assign a value to that variable within a sub why can't I
access this value in the second sub if I declared it page-level?

Cheers, Lerp
Nov 18 '05 #1
3 1314
You can call it from other subs.
"Lerp" <ad***@officience.ca> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
hi all,

If I have a variable declared outside the page_load sub and all other subs
on my page, and I assign a value to that variable within a sub why can't I
access this value in the second sub if I declared it page-level?

Cheers, Lerp

Nov 18 '05 #2

hi,

declare the variable as public and declare it before the page_load and other subs

then you can assign the value to it in any sub and access it from others. dont again declare the variable inside the subs

for exampl

public int i

page_loa

i = 5

method(
Response.write(i)
you will get the value of i as 5

dont declare it again inside the methods. thats the way
----- Lerp wrote: ----

hi all

If I have a variable declared outside the page_load sub and all other sub
on my page, and I assign a value to that variable within a sub why can't
access this value in the second sub if I declared it page-level

Cheers, Ler

Nov 18 '05 #3
It doesn't have to be public. It can be private and still can be accessed
from any of the subs. The only thing is to have it declared outside of a
sub or function, which the OP said he already did.
"ranganh" <ha**********@hotmail.com> wrote in message
news:75**********************************@microsof t.com...

hi,

declare the variable as public and declare it before the page_load and other subs.
then you can assign the value to it in any sub and access it from others. dont again declare the variable inside the subs.
for example

public int i;

page_load
{
i = 5;

}

method()

{
Response.write(i);
}

you will get the value of i as 5.

dont declare it again inside the methods. thats the way.
----- Lerp wrote: -----

hi all,

If I have a variable declared outside the page_load sub and all other subs on my page, and I assign a value to that variable within a sub why can't I access this value in the second sub if I declared it page-level?

Cheers, Lerp

Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: manish | last post by:
I have created a function, it gives more readability compared to the print_r function. As of print_r, it works both for array or single variable. I just want to add in it, the opton to view the...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
4
by: Gery D. Dorazio | last post by:
Gurus, If a static variable is defined in a class what is the scope of the variable resolved to for it to remain 'static'? For instance, lets say I create a class library assembly that is...
6
by: Maarten | last post by:
Here is a nice problem. I have two scripts, one calling the other with via an include. The script that is included contains a variable, a function and a call to that function. The variable needs to...
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...
2
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, When I try to compile the below code snippet, I get the compile error listed below in this question. In the lines below the loop, the variable j does not excist, however, trying to create it...
5
by: somenath | last post by:
Hi All , I have one question regarding scope and lifetime of variable. #include <stdio.h> int main(int argc, char *argv) { int *intp = NULL; char *sptr = NULL;
112
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions...
3
by: SRoubtsov | last post by:
Dear all, Do you know whether ANSI C (or some other dialects) support the following: * a variable name coincides with a type name, * a structure/union field name coincides with a type name in...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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.