Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How does one create a delete property of a user defined class?

I have a class that I made, called clsPicCell. Each clsPicCell object
has a two objects within it, a range object and a picture object (both
private objects).

I would like help on how to be able to delete a clsPicCell object, call
it xCell. The desired result is that if I code something like:

xCell.delete

it will clear the range object and delete the picture, and get rid of
the object all together. How would I do this? I was unable to find any
related topics, so point me in the direction of one if you know of it.

Thanks,

-Abe

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default How does one create a delete property of a user defined class?

I presume that xCell is an instance of the class clsPicCell. If so, then
just use

Set xCell = Nothing

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

wrote in message
oups.com...
I have a class that I made, called clsPicCell. Each clsPicCell object
has a two objects within it, a range object and a picture object (both
private objects).

I would like help on how to be able to delete a clsPicCell object, call
it xCell. The desired result is that if I code something like:

xCell.delete

it will clear the range object and delete the picture, and get rid of
the object all together. How would I do this? I was unable to find any
related topics, so point me in the direction of one if you know of it.

Thanks,

-Abe



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How does one create a delete property of a user defined class?

Tried that, but it failed to clear the range object in the Excel sheet
or delete the picture.

I am going to post the code below. For reference, cmdClear is a
command button that the user would click to clear all clsPicCell
objects that are associated with the selected range of cells.
cmdPlaceXcells is one that creates the clsPicCells (with associated
range and picture object).

The code runs, it may even be deleting the object from VBA's point of
view. However, it doesn't clear the range contents nor does it delete
the picture in the Excel spreadsheet.

Here's all the code... please let me know if you see where the issue
may be. Any help is greatly appreciated.
'==================
Private Sub cmdClear_Click()
Dim rngeSelected As Range
Set rngeSelected = ActiveWindow.RangeSelection
Dim Cell As Range
Dim xCell As clsCellPic
Dim cellAddress As String

'remove all corresponding xCells in collXcells
For Each Cell In rngeSelected
cellAddress = Cell.Address(ReferenceStyle:=xlR1C1)

For Each xCell In collXcells
If xCell.Name = cellAddress Then
collXcells.Remove Cell.Address(ReferenceStyle:=xlR1C1)
Set xCell = Nothing
End If
Next xCell

Next Cell

End Sub
'<======================

'======================
Private Sub cmdPlaceXcells_Click()
Dim rngeSelected As Range
Set rngeSelected = ActiveWindow.RangeSelection

Dim Cell As Range
Dim cellPic As clsCellPic
Dim picCopy As Picture
Dim picQCAnormal As Picture
Set picQCAnormal = _
ThisWorkbook.Worksheets("Variables").Pictures("Pic ture 158")

For Each Cell In rngeSelected

Set cellPic = New clsCellPic

With Cell.Parent 'worksheets(2)
picQCAnormal.Copy
.Paste
Set picCopy = _
.Pictures(.Pictures.Count) 'the one just pasted
End With

With cellPic
Set .ThisCell = Cell
Set .ThisPic = picCopy
.Name = Cell.Address(ReferenceStyle:=xlR1C1)
.FormulaR1C1 = "X"
End With

'This causes error if cell already has a xcell object.
On Error Resume Next
collXcells.Add cellPic, Cell.Address(ReferenceStyle:=xlR1C1)
On Error GoTo 0

Next Cell


End Sub
'<=====================================

'==========clsPicCell=============
Option Explicit
'<clsCellPic
Private mCell As Range
Private mPic As Picture
Private mName As String


Public Property Set ThisCell(vData As Range)
Set mCell = vData
End Property

Public Property Set ThisPic(vData As Picture)
Set mPic = vData
Call ReSync
End Property

Public Property Let Name(vData As String)
mName = vData
End Property

Public Property Get Name() As String
Name = mName
End Property

Public Property Get Address() As String
Address = mCell.Address(ReferenceStyle:=xlR1C1)
End Property

Public Property Let FormulaR1C1(vData As Variant)
mCell.FormulaR1C1 = vData
End Property

Public Property Get FormulaR1C1() As Variant
FormulaR1C1 = mCell.FormulaR1C1
End Property

Public Function ReSync()
With mCell
mPic.Top = .Top
mPic.Left = .Left
mPic.Width = .Width
mPic.Height = .Height
End With
End Function
'<=================================

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default How does one create a delete property of a user defined class?

Create a method in your class called (eg) "Clear" which clears the cell and deletes the picture.
After calling that just set the class instance to Nothing.

Or put some code in the class_terminate event, which should get called when you set an instance to Nothing (but I'm not absolutely
sure about scope etc in this case, so you should test that thoroughly)


--
Tim Williams
Palo Alto, CA


wrote in message oups.com...
I have a class that I made, called clsPicCell. Each clsPicCell object
has a two objects within it, a range object and a picture object (both
private objects).

I would like help on how to be able to delete a clsPicCell object, call
it xCell. The desired result is that if I code something like:

xCell.delete

it will clear the range object and delete the picture, and get rid of
the object all together. How would I do this? I was unable to find any
related topics, so point me in the direction of one if you know of it.

Thanks,

-Abe



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How does one create a delete property of a user defined class?

Thanks Tim, creating the clear method worked... though im not sure why
setting the object to nothing wouldn't delete the picture...

-Abe

Tim Williams wrote:
Create a method in your class called (eg) "Clear" which clears the cell and deletes the picture.
After calling that just set the class instance to Nothing.

Or put some code in the class_terminate event, which should get called when you set an instance to Nothing (but I'm not absolutely
sure about scope etc in this case, so you should test that thoroughly)


--
Tim Williams
Palo Alto, CA


wrote in message oups.com...
I have a class that I made, called clsPicCell. Each clsPicCell object
has a two objects within it, a range object and a picture object (both
private objects).

I would like help on how to be able to delete a clsPicCell object, call
it xCell. The desired result is that if I code something like:

xCell.delete

it will clear the range object and delete the picture, and get rid of
the object all together. How would I do this? I was unable to find any
related topics, so point me in the direction of one if you know of it.

Thanks,

-Abe




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default How does one create a delete property of a user defined class?

It is the same general idea as instantiating a word object. Setting the
instance to nothing does not close the application. Unless told to close it
does not close. Same idea here. You did not tell the range object to clear.
You just removed your pointer to that object. The range and the picture exist
on their own. The destructor runs on the object when you set it to nothing.
You have to do the housekeeping in the destructor (terminate) before loosing
your link to the object. It is sort of analagous to the housekeeping that you
have to do in C++ or Java when you destroy objects. In VB we are spoiled
because usually VB does the housekeeping for us (except in the case of
objects).
--
HTH...

Jim Thomlinson


" wrote:

Thanks Tim, creating the clear method worked... though im not sure why
setting the object to nothing wouldn't delete the picture...

-Abe

Tim Williams wrote:
Create a method in your class called (eg) "Clear" which clears the cell and deletes the picture.
After calling that just set the class instance to Nothing.

Or put some code in the class_terminate event, which should get called when you set an instance to Nothing (but I'm not absolutely
sure about scope etc in this case, so you should test that thoroughly)


--
Tim Williams
Palo Alto, CA


wrote in message oups.com...
I have a class that I made, called clsPicCell. Each clsPicCell object
has a two objects within it, a range object and a picture object (both
private objects).

I would like help on how to be able to delete a clsPicCell object, call
it xCell. The desired result is that if I code something like:

xCell.delete

it will clear the range object and delete the picture, and get rid of
the object all together. How would I do this? I was unable to find any
related topics, so point me in the direction of one if you know of it.

Thanks,

-Abe



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default How does one create a delete property of a user defined class?

That helps Jim. Thanks!
-Abe

Jim Thomlinson wrote:
It is the same general idea as instantiating a word object. Setting the
instance to nothing does not close the application. Unless told to close it
does not close. Same idea here. You did not tell the range object to clear.
You just removed your pointer to that object. The range and the picture exist
on their own. The destructor runs on the object when you set it to nothing.
You have to do the housekeeping in the destructor (terminate) before loosing
your link to the object. It is sort of analagous to the housekeeping that you
have to do in C++ or Java when you destroy objects. In VB we are spoiled
because usually VB does the housekeeping for us (except in the case of
objects).
--
HTH...

Jim Thomlinson


" wrote:

Thanks Tim, creating the clear method worked... though im not sure why
setting the object to nothing wouldn't delete the picture...

-Abe

Tim Williams wrote:
Create a method in your class called (eg) "Clear" which clears the cell and deletes the picture.
After calling that just set the class instance to Nothing.

Or put some code in the class_terminate event, which should get called when you set an instance to Nothing (but I'm not absolutely
sure about scope etc in this case, so you should test that thoroughly)


--
Tim Williams
Palo Alto, CA


wrote in message oups.com...
I have a class that I made, called clsPicCell. Each clsPicCell object
has a two objects within it, a range object and a picture object (both
private objects).

I would like help on how to be able to delete a clsPicCell object, call
it xCell. The desired result is that if I code something like:

xCell.delete

it will clear the range object and delete the picture, and get rid of
the object all together. How would I do this? I was unable to find any
related topics, so point me in the direction of one if you know of it.

Thanks,

-Abe




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
Cant delete user defined default chart type jenalee Charts and Charting in Excel 7 August 21st 09 08:00 PM
How do I delete a User defined default excel chart Jai Charts and Charting in Excel 1 November 7th 07 09:32 AM
Delete user-defined charts Lampman Charts and Charting in Excel 2 January 24th 07 01:49 AM
User-defined type collection in class module Rob[_29_] Excel Programming 2 May 31st 06 06:02 PM
Create my own Class Object for Ranges, having trouble assigning name property [email protected] Excel Programming 4 November 29th 05 06:08 PM


All times are GMT +1. The time now is 03:23 AM.

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

About Us

"It's about Microsoft Excel"