|
-
December 15th, 2012, 12:19 PM
#9
Re: [VB6]About properties...
 Originally Posted by WizBang
If there is only one instance of the sound class, then you need not use a class for it. A standard module would provide all the functionality you seek, while consuming fewer resources.
Bad news: I've more than one clsSound.
Then I wanted to avoid to pass directly as param the sound I was going to play, because Play method has several params and adding new ones it would be difficult to read the code and to write it, too. Obviously this is my personal opinion 
However, I studied hard and I finally found a good solution, that lets me to do all want. I post here 
Code:
'In clsGame
Dim m_Sound As New clsSound
Public Property Get Sound(ByVal Index As Integer) As clsSounds
Set Sound = m_Sound 'Return the instance of clsSounds
On Error Resume Next
Err.Raise 999 'Raise this err to point out that Item property can be written
Sound.Item = Index 'Pass the param
End Property
'In clsSounds
Dim m_Item As String
Public Property Let Item(ByVal n_Item As String)
If Err = 999 Then
m_Item = n_Item
Err.Clear
ElseIf Err = 0 Then
Err.Raise 383
End If
End Property
Public Property Get Item() As String
Item = m_Item
End Property
Public Sub Play()
Debug.Print "I'm going to play the item : " & Me.Item
End Sub
'In Form1
Private Sub Form_Load()
Dim Game As New clsGame
Call Game.Sound(<Index>).Play
Game.Sound(<Index>).Item = <something> 'Returns the err 383 - Readonly property
End Sub
This code works exactly as I want: even though it uses both a LET and a GET property, the LET property works only if it is called inside of Sound property. De facto, it's like if I have only the GET property, who returns the item currently set.
Anyway, thank you for all the time you spent to help me...
Bye bye,
Cereal Killer
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
|