Easiest way to replace item in array...

Is there a fast and efficient way to replace an item in a one dimensional array? or do I need to loop through the items and just replace the item that way?

NG,

LVL 13
nike_golfAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Uhh, you can just write over it.

YourArray(SomeNumber) = SomeValue
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nike_golfAuthor Commented:
duh... thx.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
If you are looking for a fast way to determine the INDEX of an item in an array...then No.  You have to loop over it to find the right spot that you want to overwrite.

If you need a fast way to do LOOKUPS then use a Collection instead of an Array.
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

dentabCommented:
Sorry, was jim horns answer what you were looking for?

If the array is sorted, then a binary tree search is a good way of quickly finding an item

To remove an item is harder

To swap an Item with another part of the array requires a temporary variable of the same type
  e.g.

tmpString = aitem(2)
aitem(2) = aitem(4)
aitem(4) = tmpString

Or are none of these the type of thing you are asking about?
0
dentabCommented:
Or if you want to replace all items of a certain value...

That either requires a loop (easy & fast on small arrays)
or a binary search on a sorted array, followed by a loop (harder but very fast for large arrays)
0
nike_golfAuthor Commented:
Senial moment on my behalf... thanks guy's..
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.