2013-07-05 15 views
6

Değişken öğe sayısını (kendileri başka bir sınıf nesnesi olan) tutacak bir sınıf oluşturmaya çalışıyorum. Sonra Sınıf 1 Sınıf 2 dizisi içeriyorVBA Sınıfı() nesnesi başka bir sınıfın mülkü olarak

 
' Class 2 contain each individual quote elements (OTC and MRC) 

Private pOTC As String 
Private pMRC As String 
Public Property Get OTC() As String 
    OTC = pOTC 
End Property 
Public Property Let OTC(Value As String) 
    pOTC = Value 
End Property 

Public Property Get MRC() As String 
    MRC = pMRC 
End Property 
Public Property Let MRC(Value As String) 
    pMRC = Value 
End Property 

:

Yani, Sınıf 2 var

 
Private pCurr As String 
Private pQuote(20) As Class2 

Public Property Get Curr() As String 
    Curr = pCurr 
End Property 
Public Property Let Curr(Value As String) 
    pCurr = Value 
End Property 

Public Property Set Quote(Index As Integer, cQuote As Class2) 
    Set pQuote(Index) = cQuote 
End Property 

Public Property Get Quote(Index As Integer) As Class2 
    Quote = pQuote(Index) 
End Property 

Ve ne ben yapmak istiyorum bir şey gibi:

 
Dim myQuotes As Class1 
Set myQuotes = New Class1 

myQuotes.Curr = "GBP" 
myQuotes.Quote(3).OTC = "1200" 

İlk satır ayarı myQuotes.Curr sorun değil, ancak dizinin içinde bir değer ayarlamaya çalıştığımda sonraki satır hataları h Çalışma zamanı 91 değişken nesne veya bloğu değişkeni ben yanlış yapıyorum ne olduğu

Herhangi işaretçileri ayarlanmamış ve nasıl sınıf dizideki elemanların değerlerini ayarlayabilirsiniz?

Şimdiden teşekkürler!

+0

Alex K., (meraktan) rica edebilir miyim? Neden bir alıntılar listesi kullanmak yerine onu böyle yapıyorsun? –

cevap

4

myQuotes.Quote(3) adresinde, bir sorun varsa, Property Get Quote numaralı telefonu arayın. Class2 Sizin iç dizisi örneği değil

böylece pQuote(Index) o zaman başarısız Nothing atamak deneyin myQuotes.Quote(3).OTC =Nothing bir dizi elemanı, ifade eder.

pQuote(Index) öğesinin izlendiğinden emin olmalısınız; talep üzerine bunu yapabilirsiniz:

Public Property Get Quote(Index As Integer) As Class2 
    If (pQuote(Index) Is Nothing) Then Set pQuote(Index) = New Class2 
    Set Quote = pQuote(Index) 
End Property 

(Not gerekli Set)

Veya Class1 bir intitialisation rutin ekleyerek

: sayesinde altındadır sorununuza çözümü yanında

Private Sub Class_Initialize() 
    Dim Index As Long 
    For Index = 0 To UBound(pQuote) 
     Set pQuote(Index) = New Class2 
    Next 
End Sub 
+0

Teşekkürler! İşe yaradı!! Sınıf 1'de de okunması gereken başka bir hata da buldum. ** Set Quote = pQuote (Index) **: 'public Property Get Al (Integer As Integer) Class2 Set Quote = pQuote (Index) End Property' – freudian

0

Belki Sen Class1 Yeni Class2 olarak belirlemek gerekir

Public Property Let Quote(Index As Integer, cQuote As Class2) 
    Set pQuote(Index) = cQuote 
End Property 
1

olmalıdır:

For intI = LBOUND(pQuote) to UBOUND(pQuote) 
    Set pQuote(intI) = New Class2 
Next IntI 

Eğer nihai komut Class1 ile yapmak gibi.

İlgili konular