Solved

vbscript object oriented class within class

Posted on 2014-12-21
8
165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

734 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