Solved

vbscript object oriented class within class

Posted on 2014-12-21
8
140 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 15

Expert Comment

by:ChloesDad
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
sure why not
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

763 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

7 Experts available now in Live!

Get 1:1 Help Now