Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Deletion from array

Posted on 2003-03-17
8
Medium Priority
?
166 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
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
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!

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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, 5 hours left to enroll

569 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