Results 1 to 2 of 2

Thread: Subs

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2005
    Posts
    124

    Arrow Subs

    I have seen this code in many places but I have no idea what it does. I know how to use Subroutines but I have no idea what this is:

    VB Code:
    1. Private Sub New()
    2.     ***CODE***
    3. End Sub

    The thing that I want to know is the "New" part. Any help is appreciated.
    I never know what to put in this section...



    So sue me... ... ... I'm just kidding...


    www.fat-pie.com Flash Movies... You gotta see 'em to believe 'em!

  2. #2
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    Re: Subs

    It is a constructor for a class.

    VB Code:
    1. Public class Cat
    2.  
    3. private _MyName as string = nothing
    4.  
    5. '###########
    6. Public Sub New(byval name as string)
    7.     _MyName = name
    8. End Sub
    9. '###########
    10.  
    11. Public Sub Meow()
    12.     MessageBox.Show("Meow, my name is " & _MyName)
    13. End Sub
    14.  
    15. End Class

    Then use this to demonstrate it...

    VB Code:
    1. Dim MyCat as cat = New Cat("Tiddles")
    2. MyCat.Meow()

    A constructor is used to specify zero or more parameters of a class (VB6 did not support Constructors) and is also used to set up the class so its ready for use.

    Constructors can be a complex topic as they can be used for a lot of different things, and classes can even have multiple constructors, each with a different set of parameters.
    Last edited by wossname; Jul 12th, 2005 at 05:31 AM.
    I don't live here any more.

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