Basic Constants

Constants utilitzades als programes Basic

Constants booleanes

Nom

Tipus

Valor

True

Boolean

1

False

Boolean

0


Exemple :


            Dim bPositive as Boolean
            bPositive = True
        

Constant matemàtica

Nom

Tipus

Valor

Pi

Double

3.14159265358979


Exemple :


            Function Rad2Deg( aRad as Double) As Double
             Rad2Deg = aRad * 180.00 / Pi
            End Function
        

Constants d'objecte

Nom

Tipus

Utilització

Empty

Variant

El valor Buit indica que la variable no s'ha inicialitzat.

Null

null

Indica que la variable no conté cap dada.

Nothing

Object

Assigneu l'objecte Res a una variable per suprimir una assignació anterior.


Exemple :


            SubExampleEmpty
            Dim sVar As Variant
             sVar = Empty
             Print IsEmpty(sVar) ' Returns True
            End Sub
            Sub ExampleNull
            Dim vVar As Variant
             MsgBox IsNull(vVar)
            End Sub
            Sub ExampleNothing
            Dim oDoc As Object
             Set oDoc = ThisComponent
             Print oDoc.Title
             oDoc = Nothing
             Print oDoc ‘ Error
            End Sub
        

Additional VBA constants

The following constants are available when VBA compatibility mode is enabled

warning

This function or constant is enabled with the statement Option VBASupport 1 placed before the executable program code in a module.


Named constant

Hexadecimal (decimal) value

Description

vbTrue

-1

Part of vbTriState enumeration.

vbFalse

0

Part of vbTriState enumeration.

vbUseDefault

-2

Part of vbTriState enumeration.

vbCr

\x0D (13)

CR - Carriage return

vbCrLf

\x0D\x0A (13 10)

CRLF - Carriage return and line feed

vbFormFeed

\x0c (12)

FF - Form feed

vbLf

\x0A (10)

LF - Line feed

vbNewLine

\x0D\x0A (13 10) for 32-bit Windows

\x0A (10) for other 64-bit systems

LF or CRLF

vbNullString

""

Null string

vbTab

\x09 (9)

HT - Horizontal tab

vbVerticalTab

\x0B (11)

VT - Vertical tab