|
-
Dec 2nd, 2025, 12:04 PM
#1
Thread Starter
PowerPoster
[Resolved] Object created in Sub is not valid after exit. ???
I have a bunch of these and I'd rather send a single line to a sub than have a mile-long sub creating all of them.
This doesn't work. Msgbox returns "True" (Is Nothing). ???
.
Code:
Private Sub CreateIndicator(ByRef Indicator As cIndicator, ByRef Picturebox As VB.Picturebox, ByRef Label As VB.Label, ByRef LabelPosition As LABEL_POSITION, ByRef Tooltip As String, ByRef IndicatorCollection As Collection)
Set Indicator = New cIndicator ' Is valid while in this sub. Then not.
With Indicator
Set .Picturebox = Picturebox
Set .CompanionLabel = Label
.LabelPosition = LabelPosition
.IgnoreClicks = True
.TooltipText = Tooltip
.Backcolor = &H404040
.OffColor = &H400000
.OnColor = &HC00000
.CompanionLabel.Fontsize = 8
.Refresh
End With
IndicatorCollection.Add Indicator
End Sub
Private Sub CreateIndicators()
Dim m_Indicator As cIndicator
Set colIndicators = New Collection
Set colSwitches = New Collection
CreateIndicator mw_Indicator_DND, picIndicator_DnD, lblIndicator_DnD, idx_LabelPosition_Left, "Do Not Disturb.", colIndicators
MsgBox mw_Indicator_DND Is Nothing ' Returns True.
' <snip>
end sub
Private Sub CreateIndicator(ByRef Indicator As cIndicator, ByRef Picturebox As VB.Picturebox, ByRef Label As VB.Label, ByRef LabelPosition As LABEL_POSITION, ByRef Tooltip As String, ByRef IndicatorCollection As Collection)
Set Indicator = New cIndicator
With Indicator
Set .Picturebox = Picturebox
Set .CompanionLabel = Label
.LabelPosition = LabelPosition
.IgnoreClicks = True
.TooltipText = Tooltip
.Backcolor = &H404040
.OffColor = &H400000
.OnColor = &HC00000
.CompanionLabel.Fontsize = 8
.Refresh
End With
IndicatorCollection.Add Indicator
End Sub
But this works fine.
Code:
Private Sub CreateIndicators()
Dim m_Indicator As cIndicator
Set colIndicators = New Collection
Set colSwitches = New Collection
Set mw_Indicator_DND = New cIndicator
With mw_Indicator_DND
Set .Picturebox = picIndicator_DnD
Set .CompanionLabel = lblIndicator_DnD
.LabelPosition = idx_LabelPosition_Left
.TooltipText = "Do Not Disturb."
End With
colIndicators.Add mw_Indicator_DND
<snip>
For Each m_Indicator In colIndicators
With m_Indicator
.OffColor = &H400000
.OnColor = &HC00000
.Backcolor = &H404040
.IgnoreClicks = True
.CompanionLabel.Fontsize = 8
.Refresh
End With
Next m_Indicator
Last edited by cafeenman; Dec 2nd, 2025 at 12:20 PM.
-
Dec 2nd, 2025, 12:22 PM
#2
Thread Starter
PowerPoster
Re: [Resolved] Object created in Sub is not valid after exit. ???
Well that was easy.
Code:
Private Function CreateIndicator(ByRef Picturebox As VB.Picturebox, ByRef Label As VB.Label, ByRef LabelPosition As LABEL_POSITION, ByRef Tooltip As String, ByRef IndicatorCollection As Collection) As cIndicator
Dim m_Indicator As cIndicator
Set m_Indicator = New cIndicator
With m_Indicator
Set .Picturebox = Picturebox
Set .CompanionLabel = Label
.LabelPosition = LabelPosition
.IgnoreClicks = True
.TooltipText = Tooltip
.Backcolor = &H404040
.OffColor = &H400000
.OnColor = &HC00000
.CompanionLabel.Fontsize = 8
.Refresh
End With
IndicatorCollection.Add m_Indicator
Set CreateIndicator = m_Indicator
End Function
Private Sub CreateIndicators()
Dim m_Indicator As cIndicator
Set colIndicators = New Collection
Set colSwitches = New Collection
Set mw_Indicator_DND = CreateIndicator(picIndicator_DnD, lblIndicator_DnD, idx_LabelPosition_Left, "Do Not Disturb.", colIndicators)
MsgBox mw_Indicator_DND Is Nothing ' Returns False. (yay)
<snip>
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|