I exempelvis Java har varje klass en konstruktor där man direkt när man skapar objektet tilldelar värden till dess egenskaper. Så länge får du använda class_initialize och ini-filer för att gå runt problemet. Har ett litet trix jag brukar göra...Konstruktor i VB?
Finns något liknande i VB?
Ex: Set obj = new MyObject(1, "vit", true)
Någon som vet?Sv: Konstruktor i VB?
/peterhSv: Konstruktor i VB?
'Module/GlobalMultiUse Class: Module1/Global --------------------
Option Explicit
Public Function NewClass1(Color As Long, Text As String, Icon As StdPicture) As Class1
Set NewClass1 = New Class1
NewClass1.Load Color, Text, Icon
End Function
'Class: Class1 --------------------
Option Explicit
Private mColor As Long
Private mText As String
Private mIcon As StdPicture
Friend Sub Load(Color As Long, Text As String, Icon As StdPicture)
mColor = Color
mText = Text
Set mIcon = mIcon
End Sub
Public Property Get Color() As Long
Color = mColor
End Property
Public Property Let Color(vData As Long)
mColor = vData
End Property
Public Property Get Text() As String
Text = mText
End Property
Public Property Let Text(vData As String)
Text = vData
End Property
Public Property Get Icon() As StdPicture
If mIcon Is Nothing Then Set mIcon = New StdPicture
Set Icon = mIcon
End Property
Public Property Set Icon(vData As StdPicture)
Set mIcon = vData
End Property
'Form: Form1 --------------------
Option Explicit
Private Sub Command1_Click()
Dim vTemp As Class1
Set vTemp = NewClass1(vbGreen, "Test", Icon)
End Sub