PC Review


Reply
Thread Tools Rate Thread

Class programming - how to return chartobject from a class?

 
 
fredrik.kjell@gmail.com
Guest
Posts: n/a
 
      11th Oct 2006
Hi,

I have the following setup:

1. Class module "ChartHandler"
2. Module "Tester"

In ChartHandler, I have a function to return an instance of a
ChartObject. The chart is present in a worksheet in my workbook. I
successfully claim the chart with the following code:

Public Function claimChartObject(ByVal s As String) as ChartObject

Debug.Print ws.Name ' prints worksheet name correctly
Debug.Print ws.ChartObjects(s).Name ' prints the name correctly

claimChartObject = ws.ChartObjects(s)

End Function

The above function works as it should. However, when I try to get the
chartobject from my module, it fails. The code in my module is
something like this:

Dim coChart As ChartObject
Dim handler As ChartHandler ' Creates an instance of ChartHandler -
works

' Some initialization...
' ....

Set coChart = handler.claimChartObject("myChart") ' <-- this fails!

If I try to snatch the chartobject with the following line, it works:
Set coChart = Worksheets("chart").ChartObjects("myChart")

So my question is, how to I return the chartobject from the class?? I
tried changing "Public Function" to "Property Get" but without success.

Any help much appreciated!

Fredrik

 
Reply With Quote
 
 
 
 
RaceEend
Guest
Posts: n/a
 
      11th Oct 2006
(E-Mail Removed) wrote:

> Hi,
>
> I have the following setup:
>
> 1. Class module "ChartHandler"
> 2. Module "Tester"
>
> In ChartHandler, I have a function to return an instance of a
> ChartObject. The chart is present in a worksheet in my workbook. I
> successfully claim the chart with the following code:
>
> Public Function claimChartObject(ByVal s As String) as ChartObject
>
> Debug.Print ws.Name ' prints worksheet name correctly
> Debug.Print ws.ChartObjects(s).Name ' prints the name correctly
>
> claimChartObject = ws.ChartObjects(s)
>
> End Function
>
> The above function works as it should. However, when I try to get the
> chartobject from my module, it fails. The code in my module is
> something like this:
>
> Dim coChart As ChartObject
> Dim handler As ChartHandler ' Creates an instance of ChartHandler -
> works
>
> ' Some initialization...
> ' ....
>
> Set coChart = handler.claimChartObject("myChart") ' <-- this fails!
>
> If I try to snatch the chartobject with the following line, it works:
> Set coChart = Worksheets("chart").ChartObjects("myChart")
>
> So my question is, how to I return the chartobject from the class?? I
> tried changing "Public Function" to "Property Get" but without
> success.
>
> Any help much appreciated!
>
> Fredrik


You must make an instance of the class
Dim handler As New ChartHandler

or
Dim Handler as ChartHandler
Set Handler = New ChartHandler



--

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      11th Oct 2006
Fredrik,
Because you are returning an object, you need the Set keyword.

Public Function claimChartObject(ByVal s As String) as ChartObject
Set claimChartObject = ws.ChartObjects(s)
End function

NickHK

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I have the following setup:
>
> 1. Class module "ChartHandler"
> 2. Module "Tester"
>
> In ChartHandler, I have a function to return an instance of a
> ChartObject. The chart is present in a worksheet in my workbook. I
> successfully claim the chart with the following code:
>
> Public Function claimChartObject(ByVal s As String) as ChartObject
>
> Debug.Print ws.Name ' prints worksheet name correctly
> Debug.Print ws.ChartObjects(s).Name ' prints the name correctly
>
> claimChartObject = ws.ChartObjects(s)
>
> End Function
>
> The above function works as it should. However, when I try to get the
> chartobject from my module, it fails. The code in my module is
> something like this:
>
> Dim coChart As ChartObject
> Dim handler As ChartHandler ' Creates an instance of ChartHandler -
> works
>
> ' Some initialization...
> ' ....
>
> Set coChart = handler.claimChartObject("myChart") ' <-- this fails!
>
> If I try to snatch the chartobject with the following line, it works:
> Set coChart = Worksheets("chart").ChartObjects("myChart")
>
> So my question is, how to I return the chartobject from the class?? I
> tried changing "Public Function" to "Property Get" but without success.
>
> Any help much appreciated!
>
> Fredrik
>



 
Reply With Quote
 
fredrik.kjell@gmail.com
Guest
Posts: n/a
 
      11th Oct 2006

Eend:

Thanks, aldready done that but I excluded that part in my code-snippet

NickHK:

Terrific, that did the trick. Many thanks

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a base class method return an object of an inherited class typ Ethan Strauss Microsoft C# .NET 12 12th Jan 2008 12:41 AM
call a mnuFileNew_Click method from a Main MDI class from another class (can be a MdiChild class.. )? M. G, Microsoft Dot NET Framework Forms 1 31st May 2006 06:28 AM
How to have New() in a Base Class create and return an instance of a Derived Class? Joe HM Microsoft VB .NET 4 22nd Nov 2005 09:31 PM
Make class return more than one result (class enumerating folders) Morten Snedker Microsoft VB .NET 1 3rd Jun 2005 01:21 PM
activex ,money tree dialer,RdxE Class,updaate class,YInstStarter Class damaged RUSSELL Windows XP Performance 1 23rd Nov 2003 02:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:21 AM.