Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

2 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.

3 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

4 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

5 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

6 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

7 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

8 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

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

10 Text Box controls are used when users are required to type some input (during program execution), or output is displayed on the form (known as the user- interface when the project is running) To display some text in a Text Box during program execution, assign a literal to the Text Property of the Text Box (Does not have a CAPTION Property) txtMessage.Text = “Hello World” Text Boxes

11 In this example, whatever the user enters into the Text property of the Text Box (txtName) is assigned to the Caption property of the Label (lblName) lblName.Caption = txtName.Text

12 Frames are used as containers for other controls Groups of Option Buttons or Check Boxes can be placed in frames Using frames to group controls makes the forms easier to understand Set a Frames Caption Property to display the words on the user-interface, on the top edge of the Frame Frames

13 Allows the user to select or deselect an option In a group of Check Boxes, any number of them may be selected The Value property of a Check Box is set to 0 if unchecked, 1 if checked, or 2 if disabled (greyed) 0 = vbUnchecked 1 = vbChecked Check Boxes

14 Use only when one Option of a group maybe selected Any Option Buttons placed directly on a Form, function as a Form Group A group of Option Buttons inside a Frame function together as a Frame Group The Value property of an Option Button is set to True if selected, or to False if unselected Option Buttons

15 Images An Image control holds a picture An Images Picture property can be set to a file with an extension of.BMP,.GIF,.JPG

16 Writing Windows Apps. with VB The Windows GUI Text boxes Frame Labels Option buttons Check boxes Command buttons Image Picture box

17 We want to create a program where the height property value of a text box is displayed in the text box, while further printing the contents of the text box onto the form A Practical Example (using Text Boxes)

18 A variable (X) is declared as an integer Data Type, meaning it can only accept numeric values The Text Box is named BoxContents The Variable X is assigned the value of the Height property of BoxContents (Text Box) The Text property of BoxContents consists of a literal and the value of the variable X The Text in BoxContents is also printed on the form

19

20 Before Project Execution During Project Execution

21 Additional Instructions Make the Text Box blank once the contents have been printed Notify the user that the Text Box is blank Add this Code to the End of the Sub-Procedure BoxContents.Text =“” ‘Empties whatever is in the text box Print “The Text Box (BoxContents) is now blank” ‘Prints this message on the form


Download ppt "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."

Similar presentations


Ads by Google