?
Solved

Deletion from array

Posted on 2003-03-17
8
Medium Priority
?
162 Views
Last Modified: 2010-05-03
Hi actually i am stuck in the arrays.i am doing vb.net and now i wana delete and item from list box as well as from mine array to.i can delete the last number but if i wana delete the middle or any in between number then i can't delete from array.can u plz tell how can i do this with an example.
                                thanks a lot
0
Comment
Question by:NZDevdas
[X]
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
8 Comments
 

Author Comment

by:NZDevdas
ID: 8157276
thanx a lot
0
 
LVL 11

Expert Comment

by:rdrunner
ID: 8157387
I think a collection would be better if you want to delete also from the middle...

If you use an array you have to move all items one spot back and then redim the array...

If you want to be really fast then use the API function copymemory (carefull if you dont tidy up you can cause memory leaks)
0
 

Accepted Solution

by:
sinistershadow earned 152 total points
ID: 8161725
I hope this helps:



Function RemoveItem(ItemArray() As String, ItemNum As Long) As Boolean
'ItemArray() is the actual array to be edited. Just make
'enter the name of the array.
'ItemNum is the number of the item within the array that
'you wish to remove. e.g. If your using a default array
'specifying ItemNum as 0 will remove the first item from
'the array.
'If successful then RemoveItem will return True
'If for some odd reason something goes wrong it will return
'False
'You will need to temporarily hold the value that this
'returns for it to work, even if you have no use for the
'value.
'Example1: Print RemoveItem(StringArray, 3)
'Example2: Temp = RemoveItem(PointlessArray, 793896)

Dim ArrayNum As Long

On Error GoTo ErrorHandle

ArrayNum = ItemNum

Do
    ItemArray(ArrayNum) = ItemArray(ArrayNum + 1)
    ArrayNum = ArrayNum + 1
Loop Until ArrayNum = UBound(ItemArray())

ReDim Preserve ItemArray(UBound(ItemArray()) - 1)
RemoveItem = True
Exit Function

ErrorHandle:
RemoveItem = False
End Function


NB: I wrote this using VB6 so if you do encounter errors because of .NET I'm afraid I won't be able to help.

Sinister Shadow
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 30

Assisted Solution

by:Mayank S
Mayank S earned 148 total points
ID: 8164700
list1.RemoveItem (index)

deletes an item specified by 'index' from the listbox.

0
 

Expert Comment

by:CleanupPing
ID: 8899989
NZDevdas:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 8982900
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in a week or two.  I would appreciate any comments by the experts that would help me in making a recommendation.
It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp

GPrentice00
Cleanup Volunteer
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 8983504
A simple solution has been already provided, NZDevdas.
0
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9034023
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Split between sinistershadow and mayankeagle

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

764 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