VB6 Class Init Params


Author: Dave
Date: 03.14.18 - 4:24am



Some people, myself included, wished vb6 allowed you to set some default parameters when you first create a class. Its just a small shortcut but its handy, especially if you have to set like 5-6 parameters. Upon further reflection this is a non-issue.
VB.net

dim c as new class1(1,"dog")
c.someMethod()


Traditional VB6 dim c as new class1 c.index = 1 c.name = "dog" c.someMethod()
Honestly though it doesn't take much foresight to reduce the vb6 code down to 2 lines as well which is functionally equivalent. Consider the following:
Dim c As New Class1
Call c.init(1, "dog").someMethod
Public index
Public name

Function init(i, n) As Class1
    index = i
    name = n
    Set init = Me
End Function

Function someMethod()
    MsgBox "Index: " & index & " Name: " & name
End Function


Universally default parameters of course are still set in class_initialize.




Comments: (0)

 
Leave Comment:
Name:
Email: (not shown)
Message: (Required)
Math Question: 28 + 49 = ? followed by the letter: S 



About Me
More Blogs
Main Site
Posts: (All)
2024 ( 2 )
2023 ( 9 )
2022 ( 4 )
2021 ( 2 )
2020 ( 4 )
2019 ( 5 )
2018 (6)
     VB6 UDTs
     VB6 Debugger View As Hex tooltips
     VB6 - C Share registry data
     VB6 Addin Missing Menus
     VB6 Class Init Params
     VB6 isIn function
2017 (6)
     Python and VB6
     Python pros and cons
     download web Dir
     vc rand in python
     VB6 Language Enhancement
     Register .NET as COM
2016 ( 22 )
2015 ( 15 )
2014 ( 25 )
2013 ( 4 )
2012 ( 10 )
2011 ( 7 )
2010 ( 11 )
2009 ( 3 )