Solved

vbscript object oriented class within class

Posted on 2014-12-21
8
143 Views
Last Modified: 2015-04-14
OK, so my questions is probably really a general oo question but I will ask it here for vbscript.  (I know it is a bad language but I have to use it)

I have a log class CLogger, you can find more: https://github.com/miyamiya/VBSdoc/blob/master/CLogger.vbs


I have a GenericSystem class:

Class GenericSystem
        .....
	'' Constructor
	Private Sub Class_Initialize()
             Set myLogger = New CLogger
             .........
	End Sub
        .....
End Class

Open in new window


I have sub class called PCSystem...

How do I call myLogger in the subclass? It would be helpful to only call the cLogger in the GenericSystem rather than have to recreate it in every subclass....


Thanks!
0
Comment
Question by:adamc817
  • 4
  • 4
8 Comments
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40511938
You cant directly call a member of a parent class in a sub class.

What you can do is make a CLogger property in the sub class, and pass a reference to it when you define the sub class in the parent class.

Class GenericSystem
        .....
	'' Constructor
	Private Sub Class_Initialize()
             Set myLogger = New CLogger
             mySubClass.CLogger = myLogger

             .........
	End Sub
        .....
End Class

Open in new window

0
 

Author Comment

by:adamc817
ID: 40511990
Thanks for the quick response...

That sounds perfect!

One question does mySubClass need to be defined in the constructor as well?
0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40512033
It needs to be a property, or a private variable within the class. If its defined in the constructor then it will only be available in the constructor.
0
 

Author Comment

by:adamc817
ID: 40512182
ok, so I have this:

Class GenericSystem
	'' Properties
	Private p_strName
	Private PCSystem
	
	'' Constructor
	Private Sub Class_Initialize()
		....
		Set p_vbLogger = New CLogger
 		PCSystem.CLogger = p_vbLogger

	End Sub

End CLass

Open in new window


But how do I call that in my subClass...

Class PCSystem
	'' Properties
	Private CLASSSYSTEM

	'' Constructor
	Private Sub Class_Initialize()
		Set CLASSSYSTEM= new GenericSystem

		
	End Sub


End Class

Open in new window



THANKS!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Expert Comment

by:ChloesDad
ID: 40513268
In Class PCSystem you need a public property for the logger, otherwise this line

PCSystem.Clogger = p_vbLogger

will crash

Try

Public CLogger as CLogger

After the class declaration in the subclass
0
 

Author Comment

by:adamc817
ID: 40513589
this does not seem to be helping....

I tried that line many different places without success.

I finally tried:

      Public Property Let CLogger(in_vbLogger)
            CLASSSYSTEM.p_CLogger = in_vbLogger
      End Property

and:
         Public pc_CLogger

In the PCSystem class but this failed as well.....

Can you be more specific?
0
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
ID: 40514989
You declare a property like this in vbscript

Private m_logger as C_Logger
    ' Logger property.
    Public Property Get Logger()
        Logger = m_Logger
    End Property

    Public Property Let Logger(value)
        m_logger = value
    End Property

Open in new window

0
 

Author Closing Comment

by:adamc817
ID: 40724401
sure why not
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an explanation of a simple data model to help parse a JSON feed
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now