|
-
December 13th, 2012, 04:12 AM
#3
Re: [VB6]About properties...
You're right: I was just a bit confused with my explaination. I'll try to be cleaner, even though I don't know how to explain...
I wish that, when I call the Play method in this way,
Code:
Game.Sounds("C:\WINDOWS\Chimes.WAV").Play
the method read the param Item of Sounds property and sounds it.
But as well as it isn't possible, I have to keep Item into an upper level (e.g. into a bas module) so that clsSound can read it. This solution forces me to have a module only for this variable, and I don't like.
I thought to save Item into registry and read from it when I had to play it, but also this solution doesn't satisfy me.
However now I've found a middle way, that's something like this (I'm not sure I'm writing right 'cause at the moment I don't have my project):
Code:
'clsGame
Dim m_Sounds As New clsSound
Public Property Get Sounds(ByVal Item As String) As clsSound
Dim tmp As String: tmp = m_Sounds.Sound(Item)
Set Sounds = m_Sounds
End Property
'clsSound
Dim OK As Boolean
Public Property Get Sound(Optional ByVal Item As Variant) As String
Static m_Item As String
If Not IsMissing(Item) Then
m_Item = Item
OK = True
Else
Sound = m_Item
End If
End Property
Public Sub Play()
If OK Then
Debug.Print Me.Sound
OK = False
End If
End Sub
'Somewhere else in your code
Dim Game As New clsGame
Call Game.Sounds("C:\WINDOWS\CHIMES.WAV").Play
It should work... In the morning I'll look my project and I'll correct the post if it is not correct...
Anyway, I'd be glad if you could be more accurate into describing me the process about how to create default properties.
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
|