Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General / July 2009



Tip: Looking for answers? Try searching our database.

Resizing Array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Webbiz - 29 Jul 2009 01:23 GMT
Suppose you have a set of arrays that contain one extra element at the
end that you do not need. You want to remove it before sending the
array on into another function that will do calculations on its
values.

Okay, what I have done is this:

Redim Preserve MyArray(UBound(MyArray)-1)

This works fine for removing the last array element, EXCEPT when there
is only one element, MyArray(0). Here you get an error.

So what I have done is this:

If UBound(MyArray) > 0 then Redim Preserve MyArray(UBound(MyArray)-1)

It's a lot of verbage though, so I'm thinking that maybe there is a
better way to do this?

Thanks.

Webbiz
Nobody - 29 Jul 2009 01:31 GMT
> Suppose you have a set of arrays that contain one extra element at the
> end that you do not need. You want to remove it before sending the
[quoted text clipped - 14 lines]
> It's a lot of verbage though, so I'm thinking that maybe there is a
> better way to do this?

Yes:

Sub RemoveLastElement(ByRef a() As Single)
   If UBound(a) > 0 Then
       Redim Preserve a(UBound(a)-1)
   End If
End Sub
Larry Serflaten - 29 Jul 2009 02:14 GMT
> It's a lot of verbage though, so I'm thinking that maybe there is a
> better way to do this?

It is a dynamic array.  Somewhere in your code you've created it to include
one extra element.  Why is that?

When you create it the first time, omit that extra element, problem solved....

<g>
LFS
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.