Groups | Blog | Home
all groups > asp.net > june 2004 >

asp.net : variable scope problem



ranganh
6/1/2004 9:16:06 PM

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


Scott M.
6/1/2004 10:09:59 PM
You can call it from other subs.


[quoted text, click to view]

Lerp
6/1/2004 10:56:59 PM
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

Scott M.
6/2/2004 8:25:18 AM
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.


[quoted text, click to view]

AddThis Social Bookmark Button