Visual Basic Customization

Visual Basic Customization

Reply
*pkirill
Message 1 of 14 (112 Views)

Removing 1 item from a dynamic array?

112 Views, 13 Replies
04-22-2004 09:16 AM
Can anyone show me an example of how to remove a single item from an array? For example, if I have added items to an array to get this: item1 item2 item3 item4 item5 and I need to remove item3 so the array now consists of this: item1 item2 item4 item5 The catch being that I wouldn't know an exact number or index position - all I have is partial text string to match. So in this example I would be using: Like "*3" somewhere... right? This ties into my earlier question about identifying the total number of items in a dynamic array...
*David Urban
Message 2 of 14 (112 Views)

Re: Removing 1 item from a dynamic array?

04-22-2004 09:23 AM in reply to: *pkirill
The way I have done it in the past is to swap items 3 and 5 then do a redim preserve array(4). I don't know of a better way. if it were a listbox then you could just do a x = me.ListBox1.ListIndex listbox1.removeitem x If there is a better way for an array I would like to know. David Urban pkirill wrote: > Can anyone show me an example of how to remove a single item from an array? > For example, if I have added items to an array to get this: > > item1 > item2 > item3 > item4 > item5 > > and I need to remove item3 so the array now consists of this: > > item1 > item2 > item4 > item5 > > The catch being that I wouldn't know an exact number or index position - all > I have is partial text string to match. So in this example I would be > using: Like "*3" somewhere... right? > > This ties into my earlier question about identifying the total number of > items in a dynamic array... > >
*Mark Propst
Message 3 of 14 (112 Views)

Re: Removing 1 item from a dynamic array?

04-22-2004 09:36 AM in reply to: *pkirill
my opinion: abandon arrays, use collections "pkirill" wrote in message news:4087efae$1_3@newsprd01... > Can anyone show me an example of how to remove a single item from an array?
*pkirill
Message 4 of 14 (112 Views)

Re: Removing 1 item from a dynamic array?

04-22-2004 11:08 AM in reply to: *pkirill
I'd be happy to - after reading your other reply it sounds like a much easier option. Unfortunately for me, I know less about creating a collection than I do an array! I thought collections were built in - I did not know you could make your own. Or can you? Could you toss out an example? "Mark Propst" wrote in message news:4087f31d_2@newsprd01... > my opinion: abandon arrays, use collections > > "pkirill" wrote in message > news:4087efae$1_3@newsprd01... > > Can anyone show me an example of how to remove a single item from an > array? > >
*Mark Propst
Message 5 of 14 (112 Views)

Re: Removing 1 item from a dynamic array?

04-22-2004 12:58 PM in reply to: *pkirill
Sub TestCollection() Dim colStuff as New Collection colStuff.Add "Whatever" colStuff.Add "Whatever else" dim i as integer for i = 1 to 25 colStuff.Add i next colStuff.Add "Even more stuff" colStuff.Add "Even more stuff" colStuff.Add "Whatever else" colStuff.Add "Even more stuff" for i = 1 to colStuff.count debug.print colStuff(i) next set colStuff = Nothing end sub note collections are 1 based where arrays are (usually) 0 based "pkirill" wrote in message news:408809cd$1_2@newsprd01... > I'd be happy to - after reading your other reply it sounds like a much > easier option. Unfortunately for me, I know less about creating a > collection than I do an array! I thought collections were built in - I did > not know you could make your own. Or can you? Could you toss out an > example? > > > "Mark Propst" wrote in message > news:4087f31d_2@newsprd01... > > my opinion: abandon arrays, use collections > > > > "pkirill" wrote in message > > news:4087efae$1_3@newsprd01... > > > Can anyone show me an example of how to remove a single item from an > > array? > > > > > >
*Mike Tuersley
Message 6 of 14 (112 Views)

Re: Removing 1 item from a dynamic array?

04-22-2004 01:12 PM in reply to: *pkirill
Forget collections as well. Use a Dictionary - Microsoft's not Autodesk's. It takes collections to the next level - AND includes a remove item method. Here is an example of late-binding to it: Dim mDict As Object Set mDict = CreateObject("Scripting.Dictionary") Paste the code with a break and play with the mDict in the immediate window while your code is broken. You could also just set a reference to the Microsoft Scripting Runtime and use the object browser tto explore it. -- ___________________________ Mike Tuersley CADalyst's AutoCAD Clinic Rand IMAGINiT Technologies
*Mark Propst
Message 7 of 14 (112 Views)

Re: Removing 1 item from a dynamic array?

04-22-2004 01:50 PM in reply to: *pkirill
Right! I always forget about that one. Seems like I've seen some comments about why not to use them, but if you're recommending them that's enough for me! now to retrain my habits!!! Thanks Mark "Mike Tuersley" wrote in message news:1sc65ulx61qv4.15yh7kha9d80k$.dlg@40tude.net... > Forget collections as well. Use a Dictionary - Microsoft's not Autodesk's.
*pkirill
Message 8 of 14 (112 Views)

Re: Removing 1 item from a dynamic array?

04-23-2004 05:07 AM in reply to: *pkirill
Thanks, Mark and Mike - It seems collections are easier than I thought... Certainly easier than an array in this case. Thanks for all the details, much appreciated! "Mark Propst" wrote in message news:40882eba$1_3@newsprd01... > Right! > I always forget about that one. > Seems like I've seen some comments about why not to use them, but if you're > recommending them that's enough for me! > > now to retrain my habits!!! > Thanks > Mark > > "Mike Tuersley" wrote in message > news:1sc65ulx61qv4.15yh7kha9d80k$.dlg@40tude.net... > > Forget collections as well. Use a Dictionary - Microsoft's not Autodesk's. > >
*Mike Tuersley
Message 9 of 14 (112 Views)

Re: Removing 1 item from a dynamic array?

04-23-2004 07:10 AM in reply to: *pkirill
Hmmm.... only reasons I can think of are: 1. Purist - sticking to just what vba offers 2. Possibly some incompatability between different OSs I use it all the time and haven't run into any issues with it. One of my most common implementations is using it with a text file *if* the customer's other software that I am integrating with only kicks out text. I'll populate the dict with the text data so I can search, etc. 'Course if there is a valid argument against it, I'd have to re-asses my approach:smileywink: Mike -- ___________________________ Mike Tuersley CADalyst's AutoCAD Clinic Rand IMAGINiT Technologies
*Mark Propst
Message 10 of 14 (112 Views)

Re: Removing 1 item from a dynamic array?

04-23-2004 02:07 PM in reply to: *pkirill
I'm definitely not certain (hows that for a phrase? :-) ) that there are any valid reasons against it. ...just a little dust floating in the back of my cobwebbed brain hollows that thought it heard something somewhere once maybe...uh....hmm.... The other aspect I've considered in regard to either collections or dictionaries is *if* I need to store info - either in the dwg or otherwise - then I need to transfer the data from the temporary storage to an acad dictionary or store it in xml or text or whatever and somehow key that file to the dwg. Thats why I need to study your other example on xml - so that it could be transferred from the scripting dict (since that will be a convenient though transient storage medium). "Mike Tuersley" wrote in message news:k0u7e3pseyo$.g7kg2fqo2ihl$.dlg@40tude.net... > Hmmm.... only reasons I can think of are: > > 'Course if there is a valid argument against it, I'd have to re-asses my > approach:smileywink: > > Mike
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!