1Ci Support Help Center home page
Submit a request
Sign in
  1. 1Ci Support
  2. 1C:Enterprise Development Standards
  3. Code conventions
  4. Using 1C:Enterprise language structures

Local variables pre-initializing

  • Using 1C:Enterprise language structures
    • General requirements to creating 1C:Enterprise language structures
    • Moving expressions
    • Using duplicate code
    • Using compilation directives and preprocessor commands
    • Defining variable value type
    • Getting objects metadata
    • Form module event handlers attached in code
    • Using global variables in modules
    • Local variables pre-initializing
    • Using event log
See more

Scope: managed applications, mobile applications, and ordinary applications.

Best practices

Whenever a code snippet calculates values of one or several local variables, we recommend that you preliminary initialize such variables. This way you can avoid potential execution time errors when a variable value is Undefined, and the code expects a particular vaue type. For example:

If Value Then
      MyVariable = 10;
ElseIf
      // A sequence of subsequent branches
      …
EndIf;
... = MyVariable;  // If Value is not TRUE, note that MyVariable can be Undefined

Correct:

MyVariable = 0; // default value
If Value Then
      MyVariable = 10;
ElseIf
      // A sequence of subsequent branches
      …
EndIf;

... = MyVariable;  // Using a variable value that is always numerical.

This recommendation applies to large blocks If/ElseIf/Else, in which it is difficult to control variable initialization.

 

© 2020 1C INTERNATIONAL LLC www.1Ci.com Support policy