Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Class confusion

I'm working on a VBA application for creating project plans. I have a
working prototype that uses msoRectangles in which the user can type
descriptions of tasks and task-inputs. But now I need to associate data
other than a simple text string, with each task. So I'm thinking of a new
class. Silly me!

I've read all that I could find and understand about new class modules.
Specifically, I've digested Walkenbach's chapter 29, "Excel 2002 Power
Programming with VBA." But I'm still far from my objective.

I'm not looking for a detailed lesson on how to create new class modules and
all the rest of OOP, because I don't expect anyone here to do my work for
me. But, frankly, I'm so far off the mark that I don't even know where to
find the information that I need. I don't even know if I'm asking the right
questions. So I'm looking for a little guideance from this group. Here's a
sample of what I think I know and what I think I need to know. If anyone
here can direct me to a book that I can understand (I'm really very new to
OOP), I'd be most grateful.

1) How do I create a new class that builds on existing msoRectangles and the
like?

2) If each instance of a new class is destroyed when the procedure that
creates it ends, how do I store the data for the object, so that it's there
when the workbook is opened at a late date? (I'm not even sure that this
question will make much sense to folks here.)

3) How do I define a new class, so that when the user changes the text in an
msoShape, the corresponding object in my new class also gets updated?

Finally, and this is what I really hope that somebody can help me with,
where can I read _understandable_ explanations of all this OOP stuff, with
code examples that illustrate the use of existing msoShapes as the basis for
new class definitions?

Tony Rizzo


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Class confusion

Tony,
I'm no class expert but my take on all this is, in no particular order:
Any classes (or collections, objects, etc) that you create in code get
destroyed once they fall out of scope. Hence between closing and opening you
workbook, you will need to store all data somewhere and in Excel the obvious
place is a worksheet, probably hidden as that information is not necessarily
for the user to see.

There is the Shapes collection (of instances of the Shape class) which you
can iterate with something like:
Dim MyShape As Shape
Dim TempStr as String
For Each MyShape In ThisWorkbook.Sheets(1).Shapes
If MyShape.AutoShapeType = msoShapeRectangle Then
'Do something like create a new instance of your class
'TempStr=Application.WorksheetFunction.Lookup(MySh ape.Name,Arg2,Arg3
)
'MyRects.Add MyShape,TempStr,OtherInfo2
End If
Next

Your class would need some properties/methods etc
'Class MyRect --------------------------
Private mobjMyShape As Shape
Private mstrMyInfo1 As String
Private mlngMyInfo2 As Long
Private mvarMyInfo3 As Variant

Public Property Set MyShape(vData As Shape)
Set mobjMyShape = vData
End Property
Public Property Get MyShape() As Shape
Set MyShape = mobjMyShape
End Property

Public Property Let MyInfo1(vData As String)
mstrMyInfo1 = vData
End Property
Public Property Get MyInfo1() As Shape
MyInfo1 = mstrMyInfo1
End Property
-------------- End Class

You would need a collection of your MyRect classes, with an .Add, .Remove,
..Item etc.
'Class MyRects Notice the "s"---------------------------
Private mCol As Collection

Public Function Add(Optional Key As String, _
Optional ThisRect As Shape, _
Optional Info1 As String, _
Optional ......., _
Optional sKey As String) _
As MyRect
'Create a new object
Dim objNewMember As MyRect
Set objNewMember = New MyRect

With objNewMember
.Key = Key
Set .MyShape=ThisRect
.MyInfo1 =Info1
........etc
End With

'return the object created
Set Add = objNewMember
Set objNewMember = Nothing
End Function
-------------- End Class

You can then access properties by:
MyRects(KeyName).MyShape.Height=20 'Or some other property
or
If MyRects(KeyName).Info1="ThisComapnyName" Then.....

As for storing the additional info, a table of data with something like:
MyShape.Name Info1 Info2...

Classes can raise events, so for example, if the number of rectangles in
your collection reaches some limit, you raise a LimitReached event and react
accordingly.

However, depending what you doing, you may only need to do LookUps on the
table of data, rather than using classes at all.

Hope that helps.

NickHK

"Tony Rizzo" wrote in message
...
I'm working on a VBA application for creating project plans. I have a
working prototype that uses msoRectangles in which the user can type
descriptions of tasks and task-inputs. But now I need to associate data
other than a simple text string, with each task. So I'm thinking of a new
class. Silly me!

I've read all that I could find and understand about new class modules.
Specifically, I've digested Walkenbach's chapter 29, "Excel 2002 Power
Programming with VBA." But I'm still far from my objective.

I'm not looking for a detailed lesson on how to create new class modules

and
all the rest of OOP, because I don't expect anyone here to do my work for
me. But, frankly, I'm so far off the mark that I don't even know where to
find the information that I need. I don't even know if I'm asking the

right
questions. So I'm looking for a little guideance from this group. Here's

a
sample of what I think I know and what I think I need to know. If anyone
here can direct me to a book that I can understand (I'm really very new to
OOP), I'd be most grateful.

1) How do I create a new class that builds on existing msoRectangles and

the
like?

2) If each instance of a new class is destroyed when the procedure that
creates it ends, how do I store the data for the object, so that it's

there
when the workbook is opened at a late date? (I'm not even sure that this
question will make much sense to folks here.)

3) How do I define a new class, so that when the user changes the text in

an
msoShape, the corresponding object in my new class also gets updated?

Finally, and this is what I really hope that somebody can help me with,
where can I read _understandable_ explanations of all this OOP stuff,

with
code examples that illustrate the use of existing msoShapes as the basis

for
new class definitions?

Tony Rizzo




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
date confusion manzoor New Users to Excel 2 June 16th 08 03:52 PM
MDI Confusion CMoya Excel Discussion (Misc queries) 1 February 21st 08 02:11 PM
COUNTA Confusion.... [email protected] Excel Discussion (Misc queries) 8 January 31st 08 12:21 AM
Confusion..... Eric @ CMN, Evansville Excel Discussion (Misc queries) 2 December 27th 05 07:15 PM
RaiseEvent from a class contained in a 2nd class collection? Andrew[_16_] Excel Programming 2 January 6th 04 04:22 PM


All times are GMT +1. The time now is 10:06 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"