1 / 14

VBA – podstawowe reguły języka

VBA – podstawowe reguły języka. Opracowanie Janusz Górczyński wg Microsoft Help. Visual Basic Naming Rules.   Use the following rules when you name procedures , constants , variables , and arguments in a Visual Basic module : You must use a letter as the first character.

jadyn
Télécharger la présentation

VBA – podstawowe reguły języka

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VBA – podstawowe reguły języka Opracowanie Janusz Górczyński wg Microsoft Help

  2. Visual Basic Naming Rules •   Use the following rules when you name procedures, constants, variables, and arguments in a Visual Basic module: • You must use a letter as the first character. • You can't use a space, period (.), exclamation mark (!), or the characters @, &, $,# in the name. • Name can't exceed 255 characters in length.

  3. Visual Basic Naming Rules Generally, you shouldn't use any names that are the same as the functions, statements, and methods in Visual Basic. You end up shadowing the same keywords in the language. To use an intrinsic language function, statement, or method that conflicts with an assigned name, you must explicitly identify it. Precede the intrinsic function, statement, or method name with the name of the associated type library.

  4. Visual Basic Naming Rules • For example, if you have a variable called Left, you can only invoke the Left function using VBA.Left.You can't repeat names within the same level of scope. For example, you can't declare two variables named age within the same procedure. However, you can declare a private variable named age and a procedure-level variable named age within the same module. • Note   Visual Basic isn't case-sensitive, but it preserves the capitalization in the statement where the name is declared.

  5. Procedure • A named sequence of statements executed as a unit. For example, Function, Property, and Sub are types of procedures. • A procedure name is always defined at module level. • All executable code must be contained in a procedure. • Procedures can't be nested within other procedures.

  6. Constant • A named item that retains a constant value throughout the execution of a program. • A constant can be a string or numeric literal, another constant, or any combination that includes arithmetic or logical operators except Is and exponentiation. • Each host application can define its own set of constants. Additional constants can be defined by the user with the Const statement. • You can use constants anywhere in your code in place of actual values.

  7. Variable • A named storage location that can contain data that can be modified during program execution. • Each variable has a name that uniquely identifies it within its scope. • A data type can be specified or not. • Variable names must begin with an alphabetic character, must be unique within the same scope, can't be longer than 255 characters, and can't contain an embedded period or type-declaration character.

  8. Argument & module Argument A constant, variable, or expression passed to a procedure. Module A set of declarations followed by procedures.

  9. Function procedure A procedure that performs a specific task within a program and returns a value. A Function procedure begins with a Function statement and ends with an End Function statement. For example: Function MojaF(t as String) as Integer . . . . . . . . . . End Function

  10. Statement A syntactically complete unit that expresses one kind of action, declaration, or definition. A statement generally occupies a single line, although you can use a colon (:) to include more than one statement on a line. You can also use a line-continuation character (_) to continue a single logical line onto a second physical line.

  11. Method & keyword Method A procedure that acts on an object. Keyword A word or symbol recognized as part of the Visual Basic programming language; for example, a statement, function name, or operator.

  12. Type library A file or component within another file that contains standard descriptions of exposed objects, properties, and methods that are available for Automation. Object library files (.olb) contain type libraries.

  13. Scope Defines the visibility of a variable, procedure, or object. For example, a variable declared as Public is visible to all procedures in all modules in a directly referencing project unless Option Private Module is in effect. When Option Private Module is in effect, the module itself is private and therefore not visible to referencing projects. Variables declared in a procedure are visible only within the procedure and lose their value between calls unless they are declared Static.

  14. Procedure level Describes statements located within a Function, Property, or Sub procedure. Declarations are usually listed first, followed by assignments and other executable code. Note that module-level code resides outside a procedure block.

More Related