Results 1 to 6 of 6

Thread: How to Use Classes in VB?

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2002
    Location
    Toronto, Canada
    Posts
    50

    Question How to Use Classes in VB?

    Hi, I have troubles with using Classes
    First I add a Class, then I declare a variable for this class.
    And when I start using the functions of this class I get a mistake

    Does anybody know how to declare classes properly?
    Thanks!
    Best regards, Andrew

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    If the class module is called Class1, then ;

    VB Code:
    1. Private Sub Form_Load()
    2.     Dim x As Class1
    3.     Set x = New Class1
    4. End Sub
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Member
    Join Date
    Jan 2002
    Location
    Toronto, Canada
    Posts
    50

    It works

    Thanks, It works!!!!
    Best regards, Andrew

  4. #4
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    Here's some info on classes:
    They are 'objects', not variables. Objects must be Created before you can use them, and then once you're done, you have to Destroy them. This is done in vb by:

    VB Code:
    1. Set MyClass1 = New Class1 ' Create

    VB Code:
    1. Set MyClass1 = Nothing ' Destroy
    "1 4m 4 1337 #4xz0r!'
    Janus

  5. #5
    Lively Member
    Join Date
    Sep 2001
    Posts
    74

    when would you need to destory them?

    Under what circumstances would you destory a class?
    All will fall before the might of the Black Sashi...

  6. #6
    Helger
    Guest
    You don't destroy the class. Also you don't create it by declaring it.
    What you create and destroy are objects based on the class.

    plenderj and janus pointed out how to do this.

    You should always destroy the object when you're sure you won't need it ne more to free up memory space.

    Helger

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