Indhold

# TypeName-funktion; VarType-funktion

Returnerer en tekst eller en numerisk værdi, som indeholder typeinformation for en variabel.

### Syntaks:

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

### Returtype

- En tekst for TypeName efterfulgt af '()' for arrays (matricer).

- Et heltal for VarType. For arrays af type VarType bliver tallet 8192 bliver lagt til den returnerede værdi.

### Parametre:

Varname: Det variabelnavn, du ønsker at bestemme typen for.

Følgende værdier returneres:

TypeName værdier | Navngivet konstant | VarType values | Variabeltype
--- | --- | --- | ---
…() | 8192 | Array af variable
Boolean | 11 | Boolean-variabel
Byte | 17 | Byte-variabel
Date | V_DATE | 7 | Date-variabel
Currency | V_CURRENCY | 6 | Currency-variabel (valuta)
Double | V_DOUBLE | 5 | Decimaltalsvariabel (flydende komma) med dobbelt præcision
Error | 11 | Fejltype-variabel
Integer | V_INTEGER | 2 | Integer-variabel (heltal)
Long | V_LONG | 3 | Long heltalsvariabel (store heltal)
Object | 9 | Object-variabel
Single | V_SINGLE | 4 | Decimaltalsvariabel (flydende komma) med enkelt-præcision
String | V_STRING | 8 | String-variabel (tekststrenge)
Variant | 12 | Variant-variabel (kan indeholde alle de typer, som er specificeret ved variablens definition)
Empty | V_EMPTY | 0 | Ikke-initialiseret Variant-variabel
Null | V_NULL | 1 | Ingen gyldige data

### Fejlkoder:

5 Ugyldigt Procedurekald

### 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           _
         ,, "Datatyper i LibreOffice Basic"
        Msgbox "TypeName(table): "&TypeName(table) &Chr(13)& _
          "VarType(table)="&Vartype(table) _
          ,, "Array af Variant-værdier"
      End Sub ' TypeName_VarType_example

Relaterede emner

Const-udtryk

sætningen Dim

MsgBox-funktionen

Støt os venligst!