Partilhar via


Programação Sem-Tipos no Visual Basic

The Visual Basic compiler is capable of enforcing two rules that affect your source code:

  • Every local variable must appear in a declaration statement before being used in any other kind of statement. This rule is enforced by default.

  • Every narrowing type conversion must be specified with a type conversion keyword. This rule is not enforced by default.

Compiler Options that Change the Rules

You can change either or both of these rules by resetting corresponding compiler options. If you relax the type-conversion rule, the compiler operates under permissive type semantics, which allows you to make narrowing conversions without conversion keywords. For more information, see Verificação de Tipo no Visual Basic.

If you relax the variable-declaration rule, you can then use typeless programming, which permits you to refer to variables without first declaring them. For more information, see Declaração explícita e implícita (Visual Basic).

Typeless programming is not usually recommended, because it can lead to subtle execution errors involving data types. However, you might find it useful in some circumstances, such as porting an old application that did not declare variables.

Consulte também

Tarefas

Solucionando problemas de tipos de dados (Visual Basic)

Referência

Instrução Option Explicit (Visual Basic)

Opção declaração estrito

Conceitos

Tipos de dados no Visual Basic

Caracteres de tipo (Visual Basic)

Tipos de dados de composição (Visual Basic)

Objeto como o tipo de dados Universal (Visual Basic)

Uso eficiente de tipos de dados (Visual Basic)

Outros recursos

Tipos de dados elementares (Visual Basic)

Conversões de Tipo no Visual Basic