Results 1 to 7 of 7

Thread: Parameters in Class

  1. #1

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Thumbs up Parameters in Class

    Hi all,
    Can we pass arguments in the Class Intialise Event(Dll Creation) ?
    Please mark you thread resolved using the Thread Tools as shown

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Parameters in Class

    Nope VB6 (and earlier versions) doesn't have any constructor method that can be overwritten. You'll have to create your own Init method that can be called directly after the object is created.

  3. #3

    Thread Starter
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Parameters in Class

    Any simple Example ?
    Please mark you thread resolved using the Thread Tools as shown

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Parameters in Class

    In your class module simply add a public Sub or Function like this:
    Code:
    Public Sub Init(ByVal arg1 As Long, ByVal arg2 As String)
        'do whatever
    End Sub
    You'll then have to call the Init method:
    Code:
    Dim obj As MyClassName
    Set obj = New MyClassName
    Call obj.Init(27, "Some string")

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Parameters in Class

    Congratulations on 10K Joacim!

    As mentioned, you can't pass arguments to the Initialize event, but another possibility to create your own public method and pass it parameters.

    Example:
    Code:
    Set myObj = New Class1
    Call myObj(Parameter)

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Parameters in Class

    Hack - double check your coding there.... That should generate a syntax error....
    Might find this works better:
    Code:
    Call myObj.InitThis(Parameter)
    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    New Member
    Join Date
    Dec 2007
    Posts
    12

    Re: Parameters in Class

    the VBCorlib library uses the technique of creating a method named NewClassName which returns the new instance..

    Code:
    Dim o As MyClass: Set o = NewMyClass(10, 22)
    
    Public Function NewMyClass(ByVal X As Integer, ByVal Y As Integer)
        Set NewMyClass = new MyClass
        MyClass.X = X
        MyClass.Y = Y
    End Function
    I've adopted this into my own projects.

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