vba – podstawowe reguły języka

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

Upload: jadyn

Post on 05-Jan-2016

39 views

Category:

Documents


1 download

DESCRIPTION

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. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: VBA – podstawowe reguły języka

1

VBA – podstawowe reguły języka

Opracowanie Janusz Górczyński

wg Microsoft Help

Page 2: VBA – podstawowe reguły języka

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.

Page 3: VBA – podstawowe reguły języka

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.

Page 4: VBA – podstawowe reguły języka

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.

Page 5: VBA – podstawowe reguły języka

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.

Page 6: VBA – podstawowe reguły języka

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.

Page 7: VBA – podstawowe reguły języka

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.

Page 8: VBA – podstawowe reguły języka

8

Argument & module

ArgumentA constant, variable, or expression passed to a procedure.

ModuleA set of declarations followed by procedures.

Page 9: VBA – podstawowe reguły języka

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

Page 10: VBA – podstawowe reguły języka

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.

Page 11: VBA – podstawowe reguły języka

11

Method & keyword

MethodA procedure that acts on an object.

KeywordA word or symbol recognized as part of the Visual Basic programming language; for example, a statement, function name, or operator.

Page 12: VBA – podstawowe reguły języka

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.

Page 13: VBA – podstawowe reguły języka

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.

Page 14: VBA – podstawowe reguły języka

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.