variable scope problem

  • Thread starter Thread starter Lerp
  • Start date Start date
L

Lerp

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
 
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
 
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 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top