Results 1 to 8 of 8

Thread: [RESOLVED] Question about Class module

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Resolved [RESOLVED] Question about Class module

    In a class module is there a sub such as when you make an instance of the class that it is called where you can pass arguments?

    Like in Java, for example, I have a class called Square

    When I make an instance of this class I do this:

    Square sq = new Square(x1,y1,x2,y2)

    How to do this in VB for same named class


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Question about Class module

    I'm not sure if VB6 supports arguments on the create line or not, I know VB.Net does but in Vb6 you may need to create a procedure in you class that accepts those arguments and call that to initialize the class after the New

    You definitely can't dim it on the same line as you assign a value in VB6 though you can in Vb.Net

  3. #3
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Question about Class module

    The initialize event which is called when a class is created does not support arguments.

  4. #4
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Question about Class module

    VB6 doesn't support class construtor, you can only add initialize code under Class_Initialize which doesn't accept arguments.



  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Question about Class module

    I thought that may be the case, been a while since I created a class that needed this in VB6

    So you need a class and in that class you need a public sub or function that accepts the arguments then you need to call that sub/function after you create the New instance of the class

    Code:
    Dim MyClass as clsSquare
    MyClass=New clsSquare
    
    MyClass.MySub(x1,y1,x2,y2)
    Or Square could be a function in the class which may make more sense, hard to say with the info provided

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Question about Class module

    Quote Originally Posted by DataMiser View Post
    I thought that may be the case, been a while since I created a class that needed this in VB6

    So you need a class and in that class you need a public sub or function that accepts the arguments then you need to call that sub/function after you create the New instance of the class

    Code:
    Dim MyClass as clsSquare
    MyClass=New clsSquare
    
    MyClass.MySub(x1,y1,x2,y2)
    Or Square could be a function in the class which may make more sense, hard to say with the info provided
    Can the name of the sub be the same as the class name?

    Code:
    Dim MyClass as clsSquare
    MyClass=New clsSquare
    
    MyClass.clsSquare(x1,y1,x2,y2)


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  7. #7
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Question about Class module

    Quote Originally Posted by jmsrickland View Post
    Can the name of the sub be the same as the class name?

    Code:
    Dim MyClass as clsSquare
    MyClass=New clsSquare
    
    MyClass.clsSquare(x1,y1,x2,y2)
    I was doubt but after testing, i found it is accepted!!



  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Question about Class module

    OK, then that's how I will do it.

    Thanks all.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

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