Results 1 to 6 of 6

Thread: How do i use "public" variables..?

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    How do i use "public" variables..?

    i am using sockets and then with button1 i connect to another app...but then i need another button to close the connection...then i would need to make that the variable that points to the connection would be public so i can use it with the other button..how do i do that?

  2. #2

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    bmup

  3. #3
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    Public variable As Whatever
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  4. #4

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Public Listener As New TcpListener(21)
    Listener.Start()

    End Sub


    it said:
    C:\Documents and Settings\JBRANCO\My Documents\Visual Studio Projects\WindowsApplication3\Form1.vb(51): 'Public' is not valid on a local variable declaration.

  5. #5
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Dimensioning a public variable has to be done at module level. Like right underneath the line that sets the class name.
    Please rate my post.

  6. #6
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872

    public variables

    Put your declaration of your public variable above your sub/function. Not in Your sub/function. This should work. You do not need another module or class module to declare a public variable.
    try omthing like this:

    Public Listener As New TcpListener(21)
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    Listener.Start()

    End Sub

    hope it helps

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width