How do I delete an element of a Class?

Posted on 2003-03-02
Medium Priority
Last Modified: 2010-05-01
I have a class with Message type in it.

I use:

Dim oMes As CMessage

to declare it.  Then I use

For Each oMes In m_colMessages

to loop through the ones I have.  How can I delete a certain oMes within that FOR EACH loop? I tried setting it equal to nothing, as in:


but it errored...thanks
Question by:bomax
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Expert Comment

ID: 8053255
set omes=nothing.

The better will be inside a for i=1 to m_colmessages.count
set m_colmessages(i-1)=nothing.

It is safer.

The above implies the m_colmessages is a collection which I guess it is from your code extract.

Accepted Solution

Cairotes earned 150 total points
ID: 8053269
Oh, you can remove completely by doing m_colmessages.remove. It will erase the object from the collection. You will need to play a little bit for the for i=1 to ... since the deletion affects the collection count property.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

770 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