|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
test for empty array?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 "William" <willliam.schm***@eclipseaviation.com> schrieb im Newsbeitrag Maybe this helps: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. '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 > I have code that manages a dynamic array. When I delete the last item, I Try this little trick:> 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. '*** 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/ 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/ > > "William" <willliam.schm***@eclipseaviation.com> schrieb im Newsbeitrag Up to some point maybe...news:eRsyOcQTGHA.736@TK2MSFTNGP12.phx.gbl... > I put it in a function (to hide the awful syntax) and it works great... Look at this issues: http://tinyurl.com/z8njw Olaf Schmidt wrote:
> "William" <willliam.schm***@eclipseaviation.com> schrieb im Thanks for the pointer. That one *burnt* me bad! I spent many hours trying> 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 to work around it, and never did come to figure out what the problem was until that thread. Too damned elusive. **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 > "Ivar" <ivar.ekstromer***@ntlworld.com> schrieb im Newsbeitrag That's not correct in MSDN:news:B8GTf.7381$814.2716@newsfe5-win.ntli.net... > Fixed string array (variable length) Sets each element to a zero-length > string (""). In fact all BSTR-Resources are freed and the StringArray gets Zero-Pointers (vbNullString-Values) for all Members. Olaf |
|||||||||||||||||||||||