Contents

# TypeName Function; VarType Function

Returns text or a numeric value that contain type information for a variable.

### Syntax:

      TypeName (Varname As Variant) As String
      VarType (Varname As Variant) As Integer

### Return value:

- A text for TypeName suffixed with '()' for arrays.

- An integer for VarType. The number 8192 is added to the returned value for arrays of type VarType.

### Parameters:

Varname: The variable name that you want to determine the type of.

The following values are returned:

TypeName values | Named constant | VarType values | Kiểu biến
--- | --- | --- | ---
…() | 8192 | Array of variables
Boolean | 11 | Boolean variable
Byte | 17 | Byte variable
Date | V_DATE | 7 | Date variable
Currency | V_CURRENCY | 6 | Currency variable
Double | V_DOUBLE | 5 | Double-precision floating-point variable
Error | 11 | Error type variable
Integer | V_INTEGER | 2 | Integer variable
Long | V_LONG | 3 | Long integer variable
Object | 9 | Object variable
Single | V_SINGLE | 4 | Single-precision floating-point variable
String | V_STRING | 8 | String variable
Variant | 12 | Variant variable (can contain all types specified by the definition)
Empty | V_EMPTY | 0 | Uninitialized Variant variable
Null | V_NULL | 1 | Không có dữ liệu hợp lệ

### Error codes:

5 Sai gọi thủ tục

### Example:

      Sub TypeName_VarType_example
        Const __Object=9, __Error=10, __Boolean=11, __Variant=12, __Byte=17, _
          __Array = 8192, aText = "Lorem ipsum dolor sit amet, consectetur …"
        Dim int16 As Integer,  int32() As Long   ' V_INTEGER,  V_LONG
        Dim flt32!,            flt64() As Double ' V_SINGLE,   V_DOUBLE
        Dim curr@,             dat3 As Date      ' V_CURRENCY, V_DATE
        Dim strng() As String, objct() As Object ' V_STRING,   …
        Dim bool As Boolean,   unkwn(), byt3 As Byte ' …,      V_EMPTY, …
        Dim table(-3 To 5)
        MsgBox _
         TypeName(int16) &" "& Vartype(int16) &" "& V_INTEGER        &" "& Chr(13) &_
         TypeName(int32) &" "& Vartype(int32) &" "& V_LONG+__Array   &" "& Chr(13) &_
         TypeName(flt32) &" "& VarType(flt32) &" "& V_SINGLE         &" "& Chr(13) &_
         TypeName(flt64) &" "& VarType(flt64) &" "& V_DOUBLE+__Array &" "& Chr(13) &_
         TypeName(dat3)  &" "& VarType(dat3)  &" "& V_DATE           &" "& Chr(13) &_
         TypeName(curr)  &" "& VarType(curr)  &" "& V_CURRENCY       &" "& Chr(13) &_
         TypeName(atext) &" "& VarType(aText) &" "& V_STRING         &" "& Chr(13) &_
         TypeName(strng) &" "& VarType(strng) &" "& V_STRING+__Array &" "& Chr(13) &_
         TypeName(objct) &" "& VarType(objct) &" "& __Object+__Array &" "& Chr(13) &_
         TypeName(unkwn) &" "& VarType(unkwn) &" "& V_EMPTY          &" "& Chr(13) &_
         TypeName(bool)  &" "& VarType(bool)  &" "& __Boolean        &" "& Chr(13) &_
         TypeName(varnt) &" "& VarType(varnt) &" "& V_EMPTY          &" "& Chr(13) &_
         TypeName(table) &" "& VarType(table) &" "&__Variant+__Array &" "& Chr(13) &_
         TypeName(byt3)  &" "& VarType(byt3)  &" "& __Byte           _
         ,, "Data types in LibreOffice Basic"
        Msgbox "TypeName(table): "&TypeName(table) &Chr(13)& _
          "VarType(table)="&Vartype(table) _
          ,,"Array of Variant values"
      End Sub ' TypeName_VarType_example

Chủ đề Liên quan

Const Statement

Dim Statement

MsgBox Statement