PC Review


Reply
Thread Tools Rate Thread

What is the advantage of creating this Class.

 
 
WhytheQ
Guest
Posts: n/a
 
      28th Feb 2008
I wanted to create a Class, which I could reuse, to make it easy to
update the range used by charts.
So I've created a Class called "clUpdateGraph" and updated my normal
module code to use this class to update some graphs. It works. It
doesn't seem to have added any great advantage to just using 'normal'
code in a general module.

If anyone has the time could they try this Class and Source code and
tell me what I'm missing; I'm sure this would have been a good
situation to use a Class module: either it wasn't a good situation, or
my use of the class is wrong!

Any help greatly appreciated
JasonQ


'>>>>>>>>>>>>Class Module "clUpdateGraph":
Private GS As Worksheet 'graph sheet name
Private DS As Worksheet 'data sheet name
Private GN As String 'graph name
Private DA As String 'data address


'######################
'read/write string property returning sheet that graph is located in
'######################
Public Property Let GraphSheet(sGSheet As String)
Set GS = ActiveWorkbook.Sheets(sGSheet)
End Property
Public Property Get GraphSheet() As String
GraphSheet = GS.Name
End Property
'
'
'
'######################
'read/write string property returning sheet that data is located in
'######################
Public Property Let DataSheet(sDSheet As String)
Set DS = ActiveWorkbook.Sheets(sDSheet)
End Property
Public Property Get DataSheet() As String
DataSheet = DS.Name
End Property
'
'
'
'######################
'read/write string property returning name of the chart
'######################
Public Property Let GraphName(sGName As String)
GN = sGName
End Property
Public Property Get GraphName() As String
GraphName = GN
End Property
'
'
'
'######################
'read/write string property returning new address for the graph
sourcedata
'######################
Public Property Let NewDataAddress(sAddress As String)
DA = sAddress
End Property
Public Property Get NewDataAddress() As String
NewDataAddress = DA
End Property
'
'
'
'######################
'method that resets data area
'######################
Public Function UpdateGraphRange(GraphName As String) As Boolean

UpdateGraphRange = False
On Error GoTo ErrorOccured
With GS
.ChartObjects(GraphName).Chart.SetSourceData GS.Range(DA)
UpdateGraphRange = True
End With
Exit Function
ErrorOccured:
Err.Raise vbObjectError + 700001, "", "Possibly some of the
properties are not set"

End Function



'>>>>>>>>>>>>in a normal Module:
Sub UpdateGraphRanges()

Dim x As Integer
x = ThisWorkbook.Sheets("Charts").Range("Ac3")

Set myclUpdateGraph = New ClUpdateGraph
With myclUpdateGraph

.GraphSheet = "Charts"
.DataSheet = "Charts"

.NewDataAddress = "AD4:AI" & x
.UpdateGraphRange "Chart 1"

.NewDataAddress = "AG4:AI" & x
.UpdateGraphRange "Chart 2"

.NewDataAddress = "AG4:AG" & x & ",AI4:AI" & x
.UpdateGraphRange "Chart 4"

End With
Set myclUpdateGraph = Nothing

End Sub
 
Reply With Quote
 
 
 
 
Jon Peltier
Guest
Posts: n/a
 
      29th Feb 2008
In general this wouldn't necessarily be a bad thing. However, in this
specific case, I can't tell what you've done besides design a parallel
feature that does what SetSourceData does. In fact, I was thinking this
before I saw SetSourceData in the UpdateGraphRange method.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"WhytheQ" <(E-Mail Removed)> wrote in message
news:f4440e23-1d2a-480f-a10d-(E-Mail Removed)...
>I wanted to create a Class, which I could reuse, to make it easy to
> update the range used by charts.
> So I've created a Class called "clUpdateGraph" and updated my normal
> module code to use this class to update some graphs. It works. It
> doesn't seem to have added any great advantage to just using 'normal'
> code in a general module.
>
> If anyone has the time could they try this Class and Source code and
> tell me what I'm missing; I'm sure this would have been a good
> situation to use a Class module: either it wasn't a good situation, or
> my use of the class is wrong!
>
> Any help greatly appreciated
> JasonQ
>
>
> '>>>>>>>>>>>>Class Module "clUpdateGraph":
> Private GS As Worksheet 'graph sheet name
> Private DS As Worksheet 'data sheet name
> Private GN As String 'graph name
> Private DA As String 'data address
>
>
> '######################
> 'read/write string property returning sheet that graph is located in
> '######################
> Public Property Let GraphSheet(sGSheet As String)
> Set GS = ActiveWorkbook.Sheets(sGSheet)
> End Property
> Public Property Get GraphSheet() As String
> GraphSheet = GS.Name
> End Property
> '
> '
> '
> '######################
> 'read/write string property returning sheet that data is located in
> '######################
> Public Property Let DataSheet(sDSheet As String)
> Set DS = ActiveWorkbook.Sheets(sDSheet)
> End Property
> Public Property Get DataSheet() As String
> DataSheet = DS.Name
> End Property
> '
> '
> '
> '######################
> 'read/write string property returning name of the chart
> '######################
> Public Property Let GraphName(sGName As String)
> GN = sGName
> End Property
> Public Property Get GraphName() As String
> GraphName = GN
> End Property
> '
> '
> '
> '######################
> 'read/write string property returning new address for the graph
> sourcedata
> '######################
> Public Property Let NewDataAddress(sAddress As String)
> DA = sAddress
> End Property
> Public Property Get NewDataAddress() As String
> NewDataAddress = DA
> End Property
> '
> '
> '
> '######################
> 'method that resets data area
> '######################
> Public Function UpdateGraphRange(GraphName As String) As Boolean
>
> UpdateGraphRange = False
> On Error GoTo ErrorOccured
> With GS
> .ChartObjects(GraphName).Chart.SetSourceData GS.Range(DA)
> UpdateGraphRange = True
> End With
> Exit Function
> ErrorOccured:
> Err.Raise vbObjectError + 700001, "", "Possibly some of the
> properties are not set"
>
> End Function
>
>
>
> '>>>>>>>>>>>>in a normal Module:
> Sub UpdateGraphRanges()
>
> Dim x As Integer
> x = ThisWorkbook.Sheets("Charts").Range("Ac3")
>
> Set myclUpdateGraph = New ClUpdateGraph
> With myclUpdateGraph
>
> .GraphSheet = "Charts"
> .DataSheet = "Charts"
>
> .NewDataAddress = "AD4:AI" & x
> .UpdateGraphRange "Chart 1"
>
> .NewDataAddress = "AG4:AI" & x
> .UpdateGraphRange "Chart 2"
>
> .NewDataAddress = "AG4:AG" & x & ",AI4:AI" & x
> .UpdateGraphRange "Chart 4"
>
> End With
> Set myclUpdateGraph = Nothing
>
> End Sub



 
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
creating a simple class, a cat class? Ron Microsoft VB .NET 5 13th Apr 2007 03:19 AM
Is there any advantage to re-creating user accounts? =?Utf-8?B?QmF6emEgSGF6emEgUHJvYmxlbQ==?= Windows XP General 1 10th Nov 2006 08:24 PM
C# advantage (read and write n variables of class) =?Utf-8?B?UGlvTQ==?= Microsoft C# .NET 3 20th Sep 2004 08:00 AM
re: Creating COM out of a .NET class sampath Microsoft Dot NET Framework 0 27th Feb 2004 09:01 AM
Any advantage of EventArg as class or struct? Dan H. Microsoft C# .NET 6 30th Oct 2003 06:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:50 AM.