It is described correctly in the help file. It tells you what happens with numeric and string arrays.
That you tried it with VARIANTs, kudos to you for experimenting.
Announcement
Collapse
No announcement yet.
Delete one element from VARIANT-ARRAY, impossibly?
Collapse
X
-
Using a variable type without reading all there is on it is a good way to get bad data, whether its strings, numeric, or, has a name that implies the type is at variance with all other types.
It(VARIANT) does not sell itself as a catchall type of variable, but as a means to accommodate a concept foreign to PowerBASIC that gives PowerBASIC users extra ability.
The part I quoted is in at least two places in the help file 'Variant Data Types' and 'LET statement (with Variants)' and both are hyperlinked quite well to almost any mention of Variant.
And this sentence in the ARRAY DELETE help:
If expression is not present, the last element that the data is shifted out of will contain zero if array is a numeric array, or an empty string if array is a string array.
But since they were specific with the following comment they could have added an extra word or two.
ARRAY DELETE cannot be used on arrays within UDT structures or on an array of Interfaces.
Leave a comment:
-
I think he means, if arrays of variants are not valid objects of the ARRAY DELETE statement, then this restriction should be on the help file page for ARRAY DELETE along with the other restrictions, not buried in some obtuse discussion of how the VARIANT data type is implemented and requiring inference to realize.
OTOH... if the compiler is designed to support VARIANT arrays, then there is a compiler bug.
That's the problem when the observed behavior does not equal the documented behavior: you can't know if the compiler, the help file, or both the compiler and the help file are in error. All you do know is there is an error somewhere.
Leave a comment:
-
The interpreter should do all.
From the LET statement (with Variants) help:This flexibility comes at a great price in performance, so PowerBASIC limits their use to data storage and parameters only. You may assign a numeric value, a string value, or even an entire array to a Variant with the LET statement, or its implied equivalent. In the same way, you may assign one Variant value to another Variant variable, or even assign an array contained in a Variant to a compatible PowerBASIC array, or the reverse.
This is not a 'bug'.
Leave a comment:
-
with ARRAY DELETE from VARIANT's ARRAY's -> one BUG!
The interpreter should do all...
Leave a comment:
-
>.... the internal structure of the variant. No?
No.
The PB compiler is doing all that messy stuff for you. It's not a little. Be grateful.
Get answer on ARRAY DELETE from PB support. In the help file, arrays of INTERFACEs are clearly excluded from ARRAY DELETE support, but that is not the same as an array of VARIANTs.
I would try to find out directly from the publisher if the compiler is buggy or the help file is in error, for (at least) one of those statements must be true.
MCM
Leave a comment:
-
Above "works" only if you don't care about leaks.
Leave a comment:
-
Code:DIM vArrDelete(10) AS STRING * 16 AT VARPTR(vArr(0)) 'since VARIANT is 16 long, overlay it in memory then delete 'element from vArrDelete() array ARRAY DELETE vArrDelete(5)
Above "works" only if you don't care about leaks.
MCM
Leave a comment:
-
Here's a way using ARRAY DELETE:
Code:#COMPILE EXE #DIM ALL FUNCTION PBMAIN () AS LONG DIM vArr(10) AS VARIANT DIM vArrDelete(10) AS STRING * 16 AT VARPTR(vArr(0)) 'since VARIANT is 16 long, overlay it in memory then delete 'element from vArrDelete() array ARRAY DELETE vArrDelete(5) END FUNCTION
Last edited by John Gleason; 7 Aug 2009, 10:10 AM.
Leave a comment:
-
Variant variables are now supported by PowerBASIC, but their use is limited to that of a parameter assignment for conversion of data
Code:#COMPILE EXE #DIM ALL FUNCTION PBMAIN () AS LONG DIM vArr(10) AS VARIANT varArrDel(vArr(), 5) END FUNCTION FUNCTION varArrDel(vVarArray() AS VARIANT, element AS LONG) AS LONG LOCAL ii, x AS LONG x = UBOUND(vVarArray()) - 1 FOR ii = LBOUND(vVarArray()) TO x 'shift all elements down 1 once past deleted element IF ii = element THEN FOR ii = element TO x vVarArray(ii) = vVarArray(ii+1) NEXT EXIT FOR END IF NEXT vVarArray(x + 1) = 0 'set last element to 0 END FUNCTION
Leave a comment:
-
Delete one element from VARIANT-ARRAY, impossibly?
Hallo,
how can I delete one element from VARIANT array?
e.g.
Code:LOCAL vVar() AS VARIANT REDIM vVar(1 TO 10) ... ARRAY DELETE vVar(5) '<-- Error 482 in ....: Data type mismatch
Clearly, one can use sub, e.g.:
Code:SUB DelElVarArray(BYVAL lDelElementNr AS LONG, _ vVarArray() AS VARIANT) LOCAL lFirstNr AS LONG LOCAL lElements AS LONG LOCAL lNr AS LONG LOCAL lNr2 AS LONG LOCAL vVar() AS VARIANT lFirstNr = LBOUND(vVarArray) lElements = UBOUND(vVarArray) REDIM vVar(lFirstNr TO lElements) lNr = lFirstNr DO vVar(lNr) = vVarArray(lNr) INCR lNr LOOP UNTIL lNr > UBOUND(vVarArray) lElements = UBOUND(vVarArray) - 1 REDIM vVarArray(lFirstNr TO lElements) lNr = lFirstNr lNr2 = lFirstNr DO IF lNr <> lDelElementNr THEN vVarArray(lNr2) = vVar(lNr) INCR lNr2 END IF INCR lNr LOOP UNTIL lNr > lElements END SUB
ThanksLast edited by Alexander Holzer; 7 Aug 2009, 06:34 AM.Tags: None
Leave a comment: