Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vbscript object oriented class within class

Posted on 2014-12-21
8
Medium Priority
?
206 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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…
Six Sigma Control Plans

926 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