Home All Groups Group Topic Archive Search About
Author
20 Mar 2006 10:15 PM
William
I have code that manages a dynamic array.  When I delete the last item, I
set it to empty with erase(MyArray).  In C this would create a null pointer.
How do I test this array to see if it's empty?  If empty(MyArray) does not
work.

TIA,
Wm

Author
20 Mar 2006 10:28 PM
Schmidt
"William" <willliam.schm***@eclipseaviation.com> schrieb im Newsbeitrag
news:e2GtIvGTGHA.4300@TK2MSFTNGP14.phx.gbl...
> I have code that manages a dynamic array.  When I delete the last item, I
> set it to empty with erase(MyArray).  In C this would create a null
pointer.
> How do I test this array to see if it's empty?  If empty(MyArray) does not
> work.

Maybe this helps:

'API-Declares
Private Declare Function ArrPtr& Lib "msvbvm60" Alias "VarPtr" _
  (P() As Any)
Private Declare Sub RtlMoveMemory Lib "kernel32" _
  (Dst As Any, Src As Any, ByVal cb&)

'Helper-Function
Private Function SafeArrPtr(pArr As Long) As Long
  RtlMoveMemory SafeArrPtr, ByVal pArr, 4
End Function

'Usage
  Dim B() As Byte
  MsgBox SafeArrPtr(ArrPtr(B))

  ReDim B(0)
  MsgBox SafeArrPtr(ArrPtr(B))

  Erase B
  MsgBox SafeArrPtr(ArrPtr(B))


Olaf
Author
20 Mar 2006 10:35 PM
Mike D Sutton
> I have code that manages a dynamic array.  When I delete the last item, I
> set it to empty with erase(MyArray).  In C this would create a null pointer.
> How do I test this array to see if it's empty?  If empty(MyArray) does not
> work.

Try this little trick:

'***
Dim ArrayDimensioned As Boolean
ArrayDimensioned = (Not MyArray) <> -1
'***

Hope this helps,

    Mike


- Microsoft Visual Basic MVP -
E-Mail: ED***@mvps.org
WWW: Http://EDais.mvps.org/
Author
21 Mar 2006 4:46 PM
William
AWESOME!

I put it in a function (to hide the awful syntax) and it works great.

Many thanks!
William

Show quote
"Mike D Sutton" <ED***@mvps.org> wrote in message
news:%2389nb6GTGHA.5656@TK2MSFTNGP11.phx.gbl...
>> I have code that manages a dynamic array.  When I delete the last item, I
>> set it to empty with erase(MyArray).  In C this would create a null
>> pointer.
>> How do I test this array to see if it's empty?  If empty(MyArray) does
>> not
>> work.
>
> Try this little trick:
>
> '***
> Dim ArrayDimensioned As Boolean
> ArrayDimensioned = (Not MyArray) <> -1
> '***
>
> Hope this helps,
>
>    Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: ED***@mvps.org
> WWW: Http://EDais.mvps.org/
>
>
Author
21 Mar 2006 7:54 PM
Schmidt
"William" <willliam.schm***@eclipseaviation.com> schrieb im Newsbeitrag
news:eRsyOcQTGHA.736@TK2MSFTNGP12.phx.gbl...

> I put it in a function (to hide the awful syntax) and it works great...
Up to some point maybe...
Look at this issues:
http://tinyurl.com/z8njw

Olaf
Author
21 Mar 2006 8:40 PM
Karl E. Peterson
Schmidt wrote:
> "William" <willliam.schm***@eclipseaviation.com> schrieb im
> Newsbeitrag news:eRsyOcQTGHA.736@TK2MSFTNGP12.phx.gbl...
>
>> I put it in a function (to hide the awful syntax) and it works
>> great...
>
> Up to some point maybe...
> Look at this issues:
> http://tinyurl.com/z8njw

Thanks for the pointer.  That one *burnt* me bad!  I spent many hours trying
to work around it, and never did come to figure out what the problem was
until that thread.  Too damned elusive.
--
Working without a .NET?
http://classicvb.org/
Author
20 Mar 2006 10:37 PM
Ivar
**From MSDN**



Erase Statement




Reinitializes the elements of fixed-sizearrays and releases dynamic-array
storage space.



Syntax



Erase arraylist



The required arraylist argument is one or more comma-delimited array
variables to be erased.



Remarks



Erase behaves differently depending on whether an array is fixed-size
(ordinary) or dynamic. Erase recovers no memory for fixed-size arrays. Erase
sets the elements of a fixed array as follows:



Type of Array Effect of Erase on Fixed-Array Elements

Fixed numeric array Sets each element to zero.

Fixed string array (variable length) Sets each element to a zero-length
string ("").

Fixed string array (fixed length) Sets each element to zero.

FixedVariant array Sets each element toEmpty.

Array ofuser-defined types Sets each element as if it were a separate
variable.

Array of objects Sets each element to the special value Nothing.





Erase frees the memory used by dynamic arrays. Before your program can refer
to the dynamic array again, it must redeclare the array variable's
dimensions using a ReDim statement.







Show quote
"William" <willliam.schm***@eclipseaviation.com> wrote in message
news:e2GtIvGTGHA.4300@TK2MSFTNGP14.phx.gbl...
>I have code that manages a dynamic array.  When I delete the last item, I
>set it to empty with erase(MyArray).  In C this would create a null
>pointer. How do I test this array to see if it's empty?  If empty(MyArray)
>does not work.
>
> TIA,
> Wm
>
Author
20 Mar 2006 10:43 PM
Schmidt
"Ivar" <ivar.ekstromer***@ntlworld.com> schrieb im Newsbeitrag
news:B8GTf.7381$814.2716@newsfe5-win.ntli.net...

> Fixed string array (variable length) Sets each element to a zero-length
> string ("").

That's not correct in MSDN:
In fact all BSTR-Resources are freed and the StringArray gets Zero-Pointers
(vbNullString-Values) for all Members.

Olaf

AddThis Social Bookmark Button