TypeName-funksjonen; VarType-funksjonen

Returnerer tekst eller ein numerisk verdi som inneheld typeinformasjon for ein variabel.

Syntaks:


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

Returverdi:

Parametrar:

Varname: Variabelnamnet du vil finna typen for.

Desse verdiane vert returnerte:

TypeName
verdiar

Named
konstant

VarType
values

Variabel type

…()

8192

Array av variablar

Boolean

11

Boolean-variabel

Byte

17

Byte-variabel

Date

V_DATE

7

Date-variabel

Currency

V_CURRENCY

6

Currency-variabel

Double

V_DOUBLE

5

Desimalvariabel av typen Double floating point

Error

11

Feiltypevariabel

Integer

V_INTEGER

2

Integer-variabel

Long

V_LONG

3

Long heiltalsvariabel

Object

9

Object-variabel

Single

V_SINGLE

4

Desimalvariabel av typen Single-precision floating point

String

V_STRING

8

String-variabel

Variant

12

Variant-variabel (kan innehalda alle typar og vert sett av definisjonen).

Empty

V_EMPTY

0

Ikkje-initialisert Variant-variabel

Null

V_NULL

1

Ingen gyldige data


Feilkodar

5 Ugyldig prosedyreoppkall

Eksempel:


  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           _
     ,, "Datatypar i LibreOffice Basic"
    Msgbox "TypeName(table): "&TypeName(table) &Chr(13)& _
      "VarType(table)="&Vartype(table) _
      ,,"Array of Variant values"
  End Sub ' TypeName_VarType_example

Støtt oss!