Simple VB.net question

Discussion in 'OT Technology' started by morgue, Jul 27, 2006.

  1. morgue

    morgue New Member

    Joined:
    Jul 10, 2004
    Messages:
    8,278
    Likes Received:
    0
    How do I have to declare a variable to use it on multiple sub routines?

    Something like:

    Code:
     Partial Class _Default
     Inherits System.Web.UI.Page
     Public a As Integer
     
     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
     a = 1
     End Sub
     
     Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
     Button2.Text = a
     End Sub
     End Class
    
     
  2. Kewlb

    Kewlb New Member

    Joined:
    Nov 21, 2002
    Messages:
    1,510
    Likes Received:
    0
    make a public declare in your bas module file.
     
  3. morgue

    morgue New Member

    Joined:
    Jul 10, 2004
    Messages:
    8,278
    Likes Received:
    0
    it's asp.net using vb, bas module file?
     
  4. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    project-> add module
     
  5. morgue

    morgue New Member

    Joined:
    Jul 10, 2004
    Messages:
    8,278
    Likes Received:
    0
    worst examples ever...
     
  6. Slid.

    Slid. I'm a guy.

    Joined:
    Oct 25, 2001
    Messages:
    1,928
    Likes Received:
    0
    Location:
    NH
    Instead of using "Protected Sub" try using "Public Sub," your definition of a seems fine.
     
  7. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    You declare the variable in the General => Declarations section of the module you're working in; that is to say, you declare the variable at the top of the code instead of inside a Sub or a Function. Don't use "Public" or "Private" modifiers unless you need to control access permissions.
     

Share This Page