Compartilhar via


Tipo de dados booleanos (Visual Basic)

Holds values that can be only True or False. The keywords True and False correspond to the two states of Boolean variables.

Comentários

Use o Tipo de dados booleanos (Visual Basic) para conter o estado de-de dois valores tais como verdadeiro/falso, Sim/não ou em / desativado.

O valor padrão de Boolean é False.

Boolean values are not stored as numbers, and the stored values are not intended to be equivalent to numbers. You should never write code that relies on equivalent numeric values for True and False. Whenever possible, you should restrict usage of Boolean variables to the logical values for which they are designed.

Type Conversions

When Visual Basic converts numeric data type values to Boolean, 0 becomes False and all other values become True. When Visual Basic converts Boolean values to numeric types, False becomes 0 and True becomes -1.

When you convert between Boolean values and numeric data types, keep in mind that the .NET Framework conversion methods do not always produce the same results as the Visual Basic conversion keywords. This is because the Visual Basic conversion retains behavior compatible with previous versions. For more information, see "Boolean Type Does Not Convert to Numeric Type Accurately" in Solucionando problemas de tipos de dados (Visual Basic).

Programming Tips

  • Negative Numbers. Boolean is not a numeric type and cannot represent a negative value. In any case, you should not use Boolean to hold numeric values.

  • Tipo Caracteres. Boolean tem nenhum caractere de tipo literal ou identificador tipo de caractere.

  • Framework Type. O tipo correspondente na.NET Framework é o System.Boolean estrutura.

Exemplo

In the following example, runningVB is a Boolean variable, which stores a simple yes/no setting.

Dim runningVB As Boolean
' Check to see if program is running on Visual Basic engine.
If scriptEngine = "VB" Then
    runningVB = True
End If

Consulte também

Tarefas

Solucionando problemas de tipos de dados (Visual Basic)

Referência

Resumo de tipo de dados (Visual Basic)

System.Boolean

Funções de conversão de tipo (Visual Basic)

Resumo de conversão (Visual Basic)

Função CType (Visual Basic)

Conceitos

Uso eficiente de tipos de dados (Visual Basic)