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 / Win API / July 2007



Tip: Looking for answers? Try searching our database.

Remove Element From Boolean Array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ed - 20 Jul 2007 19:47 GMT
Is this a correct way to remove an item from a Boolean array?

' -----
Private Sub RemoveElement_Bool(AryVar() As Boolean, ByVal Index As Long)

   Dim byteLen As Byte
   byteLen = 2 ' ??? Boolean pointers are 2 bytes ???

   If Index < UBound(AryVar) Then
       CopyMemory ByVal VarPtr(AryVar(Index)), _
       ByVal VarPtr(AryVar(Index + 1)), _
       (byteLen) * (UBound(AryVar) - Index)
   End If
   
   If UBound(AryVar) = LBound(AryVar) Then
       Erase AryVar
   Else
       ReDim Preserve AryVar(UBound(AryVar) - 1)
   End If

End Sub
' -----

Thanks,
Ed
Ed - 20 Jul 2007 20:06 GMT
>Is this a correct way to remove an item from a Boolean array?
>
[quoted text clipped - 21 lines]
>Thanks,
>Ed

P.S. , I replaced CopyMemory with RtlMoveMemory and seems to be working
OK now, still not sure if this is the correct way of doing it, never
used these APIs before.

Thanks for any tips,
Ed
Thorsten Albers - 20 Jul 2007 20:13 GMT
Ed <nospam@hotmail.com> schrieb im Beitrag
<mk02a3l1e6476q5a8fanv9poltf2i9nlac@4ax.com>...
> Is this a correct way to remove an item from a Boolean array?
>
[quoted text clipped - 4 lines]
>
> End Sub

Private Sub RemoveElement_Bool(AryVar() As Boolean, ByVal Index As Long)
 Dim Count As Long, IndexMax As Long

 On Error Resume Next
 IndexMax = UBound(AryVar)
 Count = IndexMax - LBound(AryVar) + 1
 On Error Goto 0

 If Count = 0 Then
   Exit Sub
 Else If (Index < LBound(AryVar)) Or (Index > IndexMax) Then
   Exit Sub
 End If

 Count = Count - 1

 If Count = 0 Then
   Erase AryVar
 Else

   If Index < IndexMax Then
     CopyMemory ByRef AryVar(Index), _
                ByRef AryVar(Index + 1), _
                Len(AryVar(Index)) * Count
   End If

   ReDim Preserve AryVar(LBound(AryVar) To (IndexMax - 1))

 End If

End Sub

But this as well is not the 'correct' way since CopyMemory() bypasses the
type checking and securing methods of VB. 'Correct' would be moving of the
array items in a loop without using CopyMemory().

Signature

----------------------------------------------------------------------
THORSTEN ALBERS                       Universität Freiburg
                                               albers@
                                                      uni-freiburg.de
----------------------------------------------------------------------

Thorsten Albers - 20 Jul 2007 23:35 GMT
Thorsten Albers <albersRE@MOVEuni-freiburg.de> schrieb im Beitrag
<01c7cb01$de70f8e0$6401a8c0@xyz>...
>   On Error Resume Next
>   IndexMax = UBound(AryVar)
>   Count = IndexMax - LBound(AryVar) + 1
>   On Error Goto 0

Sorry, this should read:

On Error Resume Next
Count = UBound(AryVar) - LBound(AryVar) + 1
If Count Then IndexMax = UBound(AryVar)
On Error Goto 0

Signature

----------------------------------------------------------------------
THORSTEN ALBERS                       Universität Freiburg
                                               albers@
                                                      uni-freiburg.de
----------------------------------------------------------------------

 
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



©2009 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.