Announcement

Collapse

Documentation

All current versions of the PowerBASIC documentation are available for download/viewing here:

PowerBASIC Links
See more
See less

VARIANT Assignments don't honour variable or constant types.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • VARIANT Assignments don't honour variable or constant types.

    When a numeric variable or constant is assigned to a variant it appears that PB only creates variants of type 5 (Double) or 3 (Long) unless you specify AS Type in the assignment

    Based on some testing, it appears that unless you specifically use AS Type in your assignment
    • All Floats (variable or constant) are converted to Double (VT = 5)
    • Integral constants (including Quads) less than or equal to the maximum value of a Long are converted to Long. (VT=3)
    • Integral variables other than Quads are converted to Longs (VT = 3)
    • All Quad variables and Quad constants larger than the maximum value of a Long are converted to Double.(VT = 5)
    If you want to store a QUAD as such in a variant, you need to do something like this:
    '
    Code:
    vq1 = 77777777777777777&&
    ? STR$(VARIANTVT(vq1))  'returns 5 (double)
    vq2 =77777777777777777&& AS QUAD
    ? STR$(VARIANTVT(vq2)) 'returns 20 (quad)
    '
    Note using "AS EXT" in the assignemnt causes a compile error. It is not supported as a variant type
    Last edited by Stuart McLachlan; 22 Jun 2022, 06:14 PM.
Working...
X