Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Get that Data Type

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

  • Get that Data Type

    Ever need to find out what data type of your variable or array is?
    Well here you go

    (Special Thanks to MCM for "PROCESSS_ANY_ARRAY.BAS")

    DemoDataTypes.bas
    Code:
    #COMPILE EXE
    #INCLUDE "WIN32API.INC"
    #INCLUDE "DataTypes.inc"
    
    FUNCTION PBMAIN () AS LONG
         LOCAL i AS LONG
    '     DIM Strng(10) AS STRING * 10
         DIM Strng(10) AS STRING
         LOCAL Msg AS STRING
         LOCAL MyTestString AS STRING
         LOCAL MyTestLong AS LONG
         FOR I = 0 TO 10
              Strng(I) = "String"& STR$(i)
         NEXT
         Msg = Msg + "Array Dimensioned? = " + STR$(IsArrayDimensioned(BYVAL VARPTR(Strng()))) + $CR
         Msg = Msg + "Array Data Type = " + IsArrayDataType(BYVAL VARPTR(Strng())) + $CR
         Msg = Msg + "Array Data Type Value = " + STR$(IsArrayDataTypeValue(BYVAL VARPTR(Strng()))) + $CR
         Msg = Msg + "Array of Pointers? = " + STR$(IsArrayPointers(BYVAL VARPTR(Strng()))) + $CR
         Msg = Msg + "Array Dimensions = " + STR$(IsArrayDimensions(BYVAL VARPTR(Strng()))) + $CR
         Msg = Msg + "Array Elements = " + STR$(IsArrayElements(BYVAL VARPTR(Strng()))) + $CR
         Msg = Msg + "Array Element Size = " + STR$(IsArrayElementsSize(BYVAL VARPTR(Strng()))) + $CR
         Msg = Msg + "Array lBound = " + STR$(IsArrayLowerBoundry(BYVAL VARPTR(Strng()), 1)) + $CR
         Msg = Msg + "Array uBound = " + STR$(IsArrayUpperBoundry(BYVAL VARPTR(Strng()), 1)) + $CR
    MSGBOX Msg
    
         MyTestString = "Hello"
         MyTestLong = 12
         Msg = ""
         Msg = Msg + "String Variable Data Type = " + IsVariableDataType(MyTestString) + $CR
         Msg = Msg + "String Variable Data Type Value = " + STR$(IsVariableDataTypeValue(MyTestString)) + $CR
         Msg = Msg + "Long Variable Data Type = " + IsVariableDataType(MyTestLong) + $CR
         Msg = Msg + "Long Variable Data Type Value = " + STR$(IsVariableDataTypeValue(MyTestLong)) + $CR
    MSGBOX Msg
    END FUNCTION
    DataTypes.inc
    Code:
    '*************************************************************************************************************
    '*** Project:
    '***      DataTypes
    '*** Description:
    '***      Wrapper for getting the Data-Type of any array or Variable
    '*** Programmer:
    '***      Cliff Nichols
    '*** Based from:
    '***      'http://www.powerbasic.com/support/pbforums/showthread.php?t=24103
    '***      'FILE: PROCESSS_ANY_ARRAY.BAS
    '***      'AUTHOR: Michael Mattias Racine WI
    '***      '7/18/02
    '***      www.powerbasic.com
    '***      www.msdn.com
    '*** Post Date:
    '***      01-25-09
    '*** Last Update:
    '***
    '*** Changes, Updates, Patches, etc....
    '***
    '***
    '*** OS Versions:
    '***      Should work on 95/98/ME, NT/2000/XP/VISTA
    '*** Tested On:
    '***      XP/VISTA
    '*** PB Versions:
    '***      7, 8, 9
    '*************************************************************************************************************
    DECLARE FUNCTION IsArrayDimensioned(ArrayData() AS WORD) AS LONG
    DECLARE FUNCTION IsArrayDataType(ArrayData() AS WORD) AS STRING
    DECLARE FUNCTION IsArrayDataTypeValue(ArrayData() AS WORD) AS LONG
    DECLARE FUNCTION IsArrayPointers(ArrayData() AS WORD) AS LONG
    DECLARE FUNCTION IsArrayDimensions(ArrayData() AS WORD) AS LONG
    DECLARE FUNCTION IsArrayElements(ArrayData() AS WORD) AS LONG
    DECLARE FUNCTION IsArrayElementsSize(ArrayData() AS WORD) AS LONG
    DECLARE FUNCTION IsArrayLowerBoundry(ArrayData() AS WORD, DimensionToGet AS LONG) AS LONG
    DECLARE FUNCTION IsArrayUpperBoundry(ArrayData() AS WORD, DimensionToGet AS LONG) AS LONG
    
    DECLARE FUNCTION IsVariableDataType(BYVAL VariableName AS VARIANT) AS STRING
    DECLARE FUNCTION IsVariableDataTypeValue(BYVAL VariableName AS VARIANT) AS LONG
    
    FUNCTION IsArrayDimensioned(ArrayData() AS WORD) AS LONG
         SELECT CASE ARRAYATTR(ArrayData(), 0)
              CASE %FALSE              'False
                   FUNCTION = %FALSE
              CASE -1
                   FUNCTION = %TRUE
         END SELECT
    END FUNCTION
    
    FUNCTION IsArrayDataType(ArrayData() AS WORD) AS STRING
    '*** Possible Data Types
    '     0      BYTE                   BYTE           %VARCLASS_BYT
    '     1      WORD                   WORD           %VARCLASS_WRD
    '     2      DOUBLE-WORD            DWORD          %VARCLASS_DWD
    '     4      INTEGER                INTEGER        %VARCLASS_INT
    '     5      LONG-INTEGER           LONG           %VARCLASS_LNG
    '     6      Unsigned BIT           n/a            %VARCLASS_BIT
    '     7      SIGNED  BIT            n/a            %VARCLASS_SBT
    '     8      QUAD-INTEGER           QUAD           %VARCLASS_QUD
    '     10     SINGLE-precision       SINGLE         %VARCLASS_SNG
    '     11     DOUBLE-precision       DOUBLE         %VARCLASS_DBL
    '     12     EXTENDED-precision     EXT            %VARCLASS_EXT
    '     13     CURRENCY               CURRENCY       %VARCLASS_CUR
    '     14     EXTENDED-CURRENCY      CURRENCYX      %VARCLASS_CUX
    '     17     VARIANT                VARIANT        %VARCLASS_VRNT
    '     18     INTERFACE              INTERFACE      %VARCLASS_IFAC
    '     19     GUID                   GUID           %VARCLASS_GUID
    '     20     UDT-OR-UNION           TYPE/UNION     %VARCLASS_TYPE
    '     21     ASCIIZ-STRING          ASCIIZ/ASCIZ   %VARCLASS_ASC
    '     22     Fixed-length-STRING    STRING * n     %VARCLASS_FIX
    '     23     Dynamic-STRING         STRING         %VARCLASS_STR
    '     24     FIELD-STRING           FIELD          %VARCLASS_FLD
    '     function = ARRAYATTR(ArrayData(), 1)
         SELECT CASE ARRAYATTR(ArrayData(), 1)
              CASE %VARCLASS_BYT
                   FUNCTION = "%VARCLASS_BYT"
              CASE %VARCLASS_WRD
                   FUNCTION = "%VARCLASS_WRD"
              CASE %VARCLASS_DWD
                   FUNCTION = "%VARCLASS_DWD"
              CASE %VARCLASS_INT
                   FUNCTION = "%VARCLASS_INT"
              CASE %VARCLASS_LNG
                   FUNCTION = "%VARCLASS_LNG"
              CASE %VARCLASS_BIT
                   FUNCTION = "%VARCLASS_BIT"
              CASE %VARCLASS_SBT
                   FUNCTION = "%VARCLASS_SBT"
              CASE %VARCLASS_QUD
                   FUNCTION = "%VARCLASS_QUD"
              CASE 9
                   FUNCTION = "UNKNOWN"
              CASE %VARCLASS_SNG
                   FUNCTION = "%VARCLASS_SNG"
              CASE %VARCLASS_DBL
                   FUNCTION = "%VARCLASS_DBL"
              CASE %VARCLASS_EXT
                   FUNCTION = "%VARCLASS_EXT"
              CASE %VARCLASS_CUR
                   FUNCTION = "%VARCLASS_CUR"
              CASE %VARCLASS_CUX
                   FUNCTION = "%VARCLASS_CUX"
              CASE 15, 16
                   FUNCTION = "UNKNOWN"
              CASE %VARCLASS_VRNT
                   FUNCTION = "%VARCLASS_VRNT"
              CASE %VARCLASS_IFAC
                   FUNCTION = "%VARCLASS_IFAC"
              CASE %VARCLASS_GUID
                   FUNCTION = "%VARCLASS_GUID"
              CASE %VARCLASS_TYPE
                   FUNCTION = "%VARCLASS_TYPE"
              CASE %VARCLASS_ASC
                   FUNCTION = "%VARCLASS_ASC"
              CASE %VARCLASS_FIX
                   FUNCTION = "%VARCLASS_FIX"
              CASE %VARCLASS_STR
                   FUNCTION = "%VARCLASS_STR"
              CASE %VARCLASS_FLD
                   FUNCTION = "%VARCLASS_FLD"
              CASE > 24
                   FUNCTION = "UNKNOWN"
         END SELECT
    END FUNCTION
    
    FUNCTION IsArrayDataTypeValue(ArrayData() AS WORD) AS LONG
    '*** Possible Data Types
    '     0      BYTE                   BYTE           %VARCLASS_BYT
    '     1      WORD                   WORD           %VARCLASS_WRD
    '     2      DOUBLE-WORD            DWORD          %VARCLASS_DWD
    '     4      INTEGER                INTEGER        %VARCLASS_INT
    '     5      LONG-INTEGER           LONG           %VARCLASS_LNG
    '     6      Unsigned BIT           n/a            %VARCLASS_BIT
    '     7      SIGNED  BIT            n/a            %VARCLASS_SBT
    '     8      QUAD-INTEGER           QUAD           %VARCLASS_QUD
    '     10     SINGLE-precision       SINGLE         %VARCLASS_SNG
    '     11     DOUBLE-precision       DOUBLE         %VARCLASS_DBL
    '     12     EXTENDED-precision     EXT            %VARCLASS_EXT
    '     13     CURRENCY               CURRENCY       %VARCLASS_CUR
    '     14     EXTENDED-CURRENCY      CURRENCYX      %VARCLASS_CUX
    '     17     VARIANT                VARIANT        %VARCLASS_VRNT
    '     18     INTERFACE              INTERFACE      %VARCLASS_IFAC
    '     19     GUID                   GUID           %VARCLASS_GUID
    '     20     UDT-OR-UNION           TYPE/UNION     %VARCLASS_TYPE
    '     21     ASCIIZ-STRING          ASCIIZ/ASCIZ   %VARCLASS_ASC
    '     22     Fixed-length-STRING    STRING * n     %VARCLASS_FIX
    '     23     Dynamic-STRING         STRING         %VARCLASS_STR
    '     24     FIELD-STRING           FIELD          %VARCLASS_FLD
         FUNCTION = ARRAYATTR(ArrayData(), 1)
    END FUNCTION
    
    FUNCTION IsArrayPointers(ArrayData() AS WORD) AS LONG
         SELECT CASE ARRAYATTR(ArrayData(), 2)
              CASE %FALSE
                   FUNCTION = %FALSE
              CASE -1
                   FUNCTION = %TRUE
         END SELECT
    END FUNCTION
    
    FUNCTION IsArrayDimensions(ArrayData() AS WORD) AS LONG
         FUNCTION = ARRAYATTR(ArrayData(), 3)
    END FUNCTION
    
    FUNCTION IsArrayElements(ArrayData() AS WORD) AS LONG
         FUNCTION = ARRAYATTR(ArrayData(), 4)
    END FUNCTION
    
    FUNCTION IsArrayElementsSize(ArrayData() AS WORD) AS LONG
         FUNCTION = ARRAYATTR(ArrayData(), 5)
    END FUNCTION
    
    FUNCTION IsArrayLowerBoundry(ArrayData() AS WORD, DimensionToGet AS LONG) AS LONG
         SELECT CASE DimensionToGet
              CASE 0
                   FUNCTION = LBOUND(ArrayData())
              CASE ELSE
                   FUNCTION = LBOUND(ArrayData(), DimensionToGet)
         END SELECT
    END FUNCTION
    
    FUNCTION IsArrayUpperBoundry(ArrayData() AS WORD, DimensionToGet AS LONG) AS LONG
         SELECT CASE DimensionToGet
              CASE 0
                   FUNCTION = UBOUND(ArrayData())
              CASE ELSE
                   FUNCTION = UBOUND(ArrayData(), DimensionToGet)
         END SELECT
    END FUNCTION
    
    FUNCTION IsVariableDataType(BYVAL VariableName AS VARIANT) AS STRING
    '*** Possible Data Types
    '     0         %VT_EMPTY               An Empty Variant
    '     1         %VT_NULL                Null string
    '     2         %VT_I2                  Integer
    '     3         %VT_I4                  Long-Integer
    '     4         %VT_R4                  Single
    '     5         %VT_R8                  Double
    '     6         %VT_CY                  Currency
    '     7         %VT_DATE                Date
    '     8         %VT_BSTR                Dynamic String
    '     9         %VT_DISPATCH            IDispatch
    '     10        %VT_ERROR               Error Code
    '     11        %VT_BOOL                Boolean
    '     12        %VT_VARIANT             Variant
    '     13        %VT_UNKNOWN             IUnknown
    '     16        %VT_I1                  Byte
    '     17        %VT_UI1                 Byte
    '     18        %VT_UI2                 Word
    '     19        %VT_UI4                 DWORD
    '     20        %VT_I8                  Quad (signed)
    '     21        %VT_UI8                 Quad (unsigned)
    '     22        %VT_INT                 Integer
    '     23        %VT_UNIT                Word                          '<--- MisDocumented as %VT_UNIT
    '     24        %VT_VOID                A C-style void type
    '     25        %VT_HRESULT             COM result code
    '     26        %VT_PTR                 Pointer
    '     27        %VT_SAFEARRAY           VB Array
    '     28        %VT_CARRAY              A C-style array
    '     29        %VT_USERDEFINED          User Defined Type
    '     30        %VT_LPSTR                ANSI string
    '     31        %VT_LPWSTR               Unicode string
    '     64        %VT_FILETIME             A FILETIME value
    '     65        %VT_BLOB                 An arbitrary block of memory
    '     66        %VT_STREAM               A stream of bytes
    '     67        %VT_STORAGE              Name of the storage
    '     68        %VT_STREAMED_OBJECT      A stream that contains an object
    '     69        %VT_STORED_OBJECT        A storage object
    '     70        %VT_BLOB_OBJECT          A block of memory that represents an object
    '     71        %VT_CF                   Clipboard format
    '     72        %VT_CLSID                Class ID
    '     &H1000    %VT_VECTOR               An array with a leading count
    '     &H2000    %VT_ARRAY                Array
    '     &H4000    %VT_BYREF                A reference value
         SELECT CASE VARIANTVT(VariableName)
              CASE %VT_EMPTY                 'An Empty Variant
                   FUNCTION = "%VT_EMPTY"
              CASE %VT_NULL                  'Null string
                   FUNCTION = "%VT_NULL"
              CASE %VT_I2                    'Integer
    '               FUNCTION = "%VT_I2"
                   FUNCTION = "%VT_INTEGER"
              CASE %VT_I4                    'Long-Integer
    '               FUNCTION = "%VT_I4"
                   FUNCTION = "%VT_LONG"
              CASE %VT_R4                    'Single
    '               FUNCTION = "%VT_R4"
                   FUNCTION = "%VT_SINGLE"
              CASE %VT_R8                    'Double
    '               FUNCTION = "%VT_R8"
                   FUNCTION = "%VT_DOUBLE"
              CASE %VT_CY                    'Currency
    '               FUNCTION = "%VT_CY"
                   FUNCTION = "%VT_CURRENCY"
              CASE %VT_DATE                  'Date
                   FUNCTION = "%VT_DATE"
              CASE %VT_BSTR                  'Dynamic String
    '               FUNCTION = "%VT_BSTR"
                   FUNCTION = "%VT_STRING"
              CASE %VT_DISPATCH              'IDispatch
                   FUNCTION = "%VT_DISPATCH"
              CASE %VT_ERROR                 'Error Code
                   FUNCTION = "%VT_ERROR"
              CASE %VT_BOOL                  'Boolean
    '               FUNCTION = "%VT_BOOL"
                   FUNCTION = "%VT_BOOLEAN"
              CASE %VT_VARIANT               'Variant
                   FUNCTION = "%VT_VARIANT"
              CASE %VT_UNKNOWN               'IUnknown
                   FUNCTION = "%VT_UNKNOWN"
              CASE %VT_I1                    'Byte
    '               FUNCTION = "%VT_I1"
                   FUNCTION = "%VT_SIGNED_BYTE"
              CASE %VT_UI1                   'Byte
    '               FUNCTION = "%VT_UI1"
                   FUNCTION = "%VT_UNSIGNED_BYTE"
              CASE %VT_UI2                   'Word
    '               FUNCTION = "%VT_UI2"
                   FUNCTION = "%VT_WORD"
              CASE %VT_UI4                   'DWORD
    '               FUNCTION = "%VT_UI4"
                   FUNCTION = "%VT_DWORD"
              CASE %VT_I8                    'Quad (signed)
    '               FUNCTION = "%VT_I8"
                   FUNCTION = "%VT_SIGNED_QUAD"
              CASE %VT_UI8                   'Quad (unsigned)
    '               FUNCTION = "%VT_UI8"
                   FUNCTION = "%VT_UNSIGNED_QUAD"
              CASE %VT_INT                   'Integer
                   FUNCTION = "%VT_INT"
              CASE %VT_UINT                  'Word                        '<--- MisDocumented as %VT_UNIT
                   FUNCTION = "%VT_UINT"
              CASE %VT_VOID                  'A C-style void type
                   FUNCTION = "%VT_VOID"
              CASE %VT_HRESULT               'COM result code
                   FUNCTION = "%VT_HRESULT"
              CASE %VT_PTR                   'Pointer
                   FUNCTION = "%VT_PTR"
              CASE %VT_SAFEARRAY             'VB Array
                   FUNCTION = "%VT_SAFEARRAY"
              CASE %VT_CARRAY                'A C-style array
                   FUNCTION = "%VT_CARRAY"
              CASE %VT_USERDEFINED           'User Defined Type
                   FUNCTION = "%VT_USERDEFINED"
              CASE %VT_LPSTR                     'ANSI string
                   FUNCTION = "%VT_LPSTR"
              CASE %VT_LPWSTR                    'Unicode string
                   FUNCTION = "%VT_LPWSTR"
              CASE %VT_FILETIME                  'A FILETIME value
                   FUNCTION = "%VT_FILETIME"
              CASE %VT_BLOB                      'An arbitrary block of memory
                   FUNCTION = "%VT_BLOB"
              CASE %VT_STREAM                    'A stream of bytes
                   FUNCTION = "%VT_STREAM"
              CASE %VT_STORAGE                   'Name of the storage
                   FUNCTION = "%VT_STORAGE"
              CASE %VT_STREAMED_OBJECT           'A stream that contains an object
                   FUNCTION = "%VT_STREAMED_OBJECT"
              CASE %VT_STORED_OBJECT             'A storage object
                   FUNCTION = "%VT_STORED_OBJECT"
              CASE %VT_BLOB_OBJECT               'A block of memory that represents an object
                   FUNCTION = "%VT_BLOB_OBJECT"
              CASE %VT_CF                        'Clipboard format
                   FUNCTION = "%VT_CF"
              CASE %VT_CLSID                     'Class ID
                   FUNCTION = "%VT_CLSID"
              CASE %VT_VECTOR                    'An array with a leading count
                   FUNCTION = "%VT_VECTOR"
              CASE %VT_ARRAY                     'Array
                   FUNCTION = "%VT_ARRAY"
              CASE %VT_BYREF                     'A reference value
                   FUNCTION = "%VT_BYREF"
         END SELECT
    END FUNCTION
    
    FUNCTION IsVariableDataTypeValue(BYVAL VariableName AS VARIANT) AS LONG
    '*** Possible Data Types
    '     0         %VT_EMPTY               An Empty Variant
    '     1         %VT_NULL                Null string
    '     2         %VT_I2                  Integer
    '     3         %VT_I4                  Long-Integer
    '     4         %VT_R4                  Single
    '     5         %VT_R8                  Double
    '     6         %VT_CY                  Currency
    '     7         %VT_DATE                Date
    '     8         %VT_BSTR                Dynamic String
    '     9         %VT_DISPATCH            IDispatch
    '     10        %VT_ERROR               Error Code
    '     11        %VT_BOOL                Boolean
    '     12        %VT_VARIANT             Variant
    '     13        %VT_UNKNOWN             IUnknown
    '     16        %VT_I1                  Byte
    '     17        %VT_UI1                 Byte
    '     18        %VT_UI2                 Word
    '     19        %VT_UI4                 DWORD
    '     20        %VT_I8                  Quad (signed)
    '     21        %VT_UI8                 Quad (unsigned)
    '     22        %VT_INT                 Integer
    '     23        %VT_UNIT                Word                          '<--- MisDocumented as %VT_UNIT
    '     24        %VT_VOID                A C-style void type
    '     25        %VT_HRESULT             COM result code
    '     26        %VT_PTR                 Pointer
    '     27        %VT_SAFEARRAY           VB Array
    '     28        %VT_CARRAY              A C-style array
    '     29        %VT_USERDEFINED          User Defined Type
    '     30        %VT_LPSTR                ANSI string
    '     31        %VT_LPWSTR               Unicode string
    '     64        %VT_FILETIME             A FILETIME value
    '     65        %VT_BLOB                 An arbitrary block of memory
    '     66        %VT_STREAM               A stream of bytes
    '     67        %VT_STORAGE              Name of the storage
    '     68        %VT_STREAMED_OBJECT      A stream that contains an object
    '     69        %VT_STORED_OBJECT        A storage object
    '     70        %VT_BLOB_OBJECT          A block of memory that represents an object
    '     71        %VT_CF                   Clipboard format
    '     72        %VT_CLSID                Class ID
    '     &H1000    %VT_VECTOR               An array with a leading count
    '     &H2000    %VT_ARRAY                Array
    '     &H4000    %VT_BYREF                A reference value
         FUNCTION = VARIANTVT(VariableName)
    END FUNCTION
    Discussion can be found under "Get that Data Type Discussion"
    Last edited by Cliff Nichols; 25 Jan 2009, 11:42 AM.
    Engineer's Motto: If it aint broke take it apart and fix it

    "If at 1st you don't succeed... call it version 1.0"

    "Half of Programming is coding"....."The other 90% is DEBUGGING"

    "Document my code????" .... "WHYYY??? do you think they call it CODE? "
Working...
X