Presentation is loading. Please wait.

Presentation is loading. Please wait.

VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not.

Similar presentations


Presentation on theme: "VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not."— Presentation transcript:

1 VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not executable Comments make the project more readable and understandable The inclusion of comments is seen as good programming practice It is a good idea to comment within the logic of the project, especially if the purpose of any statement is unclear

2 The Assignment statement assigns a value to a property or variable Assignment statements operate form Right to Left, that is the value appearing on the right hand side of the equal sign (=) is assigned to the property named on the left of the equal sign (Example: lblTitle.FontSize = 12 Let lblTitle.FontSize = 12) The use of ‘Let’ is optional, and its use may improve the readability of the project code

3 When the value to assign is ‘actual text’, known as a Literal, it is enclosed in quotation marks This allows any combination of alpha and numeric characters to be typed However, if the value is numeric, (eg: 12), do not enclose it in quotation marks Do not place quotation marks around the term True or False, as VB recognises these as Special Key Terms (Blue in colour, within VB code) The End statement stops the execution of the project

4 Private Sub cmdPush_Click ‘Display the ‘Hello World’ Message lblMessage.Caption = “Hello World” End Sub *********************************************** Private Sub cmdExit_Click ‘Exit the project End End Sub Comment Assignment

5 To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window will open, with the First and Last lines of the Sub Procedure already in place, by default within VB Follow good coding conventions and Indent all lines between Private Sub and End Sub

6 Label Caption Property A Label control’s caption size is unlimited. For forms and all other controls that have captions, the limit is 255 characters.

7 Variables: Memory locations that hold data, that can be changed during project execution (eg: student names will vary as the information for each student is being processed) Constants: Memory locations that hold data that cannot change during execution (eg: however, the college which the students attend (UCC) will remain the same) Variables and Constants

8 Variables are declared, depending on where they are used and how long their value needs to be retained Variables are locations in the computers memory, which are named by the user Variables store values The values which are assigned to variables can change during project execution (the values they hold varies, hence the name) Variables

9 Variables have to be declared (the computer must be made aware of their existence) and once they have been declared, the computer allocates them (memory) storage space and assigns this area of memory a name, called an identifier Variables are declared using the DIM statement DIM Variable Name (Identifier) AS Data Type The declaration statements establish the project variables, assign names to the variables, and specify the type of data that the variables will hold The statements are non-executable (they are not executed in the flow of instructions during program execution

10 Dim stName As STRING (Declares a string variable) Dim iCounter As INTEGER (Declares an integer variable) The reserved word DIM is short for dimension, meaning size Variables can have a number of different data types A variable can only store values which correspond with the data type they are assigned

11 The data type of a variable indicates what type of information will be stored in the allocated memory space The default data type is variant The advantage of using variant data type is that it is easy, and the variables change their appearance as needed for each situation The disadvantage is that variants are less efficient than the other data types, they require more memory and operate less quickly Data Types

12 DIM Variable name (Identifier) AS Data Type Dim iYear As Integer Dim stCustName As String can also be declared as: Dim iYear As Integer, stCustName As String Also Specific Characters can be used to represent each of the Data Types Variable Declarations

13 - String ($) - Integer (%) - Currency (@) - Long Integer (&) - Single Precision (!) - Double Precision (£) Variable Declarations Dim iYear%, stCustName$, cInterest@ Data Types

14


Download ppt "VB Code Statements 3 types of VB statement The Remark statement, known as comments, are used for project documentation only Begin with an apostrophe Not."

Similar presentations


Ads by Google