340 likes | 527 Views
Working with Intrinsic Controls and ActiveX Controls. Project 2. Introduction. Intrinsic Controls – the basic set of twenty controls in the toolbox. Are a part of the .exe VB program. ActiveX Controls – exists as separate files. Files have a .ocx extension. Introduction cont……….
E N D
Working with Intrinsic Controls and ActiveX Controls Project 2
Introduction • Intrinsic Controls – the basic set of twenty controls in the toolbox. • Are a part of the .exe VB program. • ActiveX Controls – exists as separate files. • Files have a .ocx extension.
Introduction cont………. • Many routines and procedures are built into applications that are not designed for the end user.
Creating the Interface • Consists of sizing and locating the GUI and then adding the controls necessary for the user to use the form.
Form Size and Position • Height and Width property values can change the size of the form. • Top and Left property values change the position of the form.
AutoSize and BackStyle Properties • AutoSize – when set to True, the size of the control (label) will depend on the size of the caption property. • BackStyle – when set to Transparent, the color of the control below the label displays within the label’s border.
Copying Controls • You can copy and paste controls. • A message will ask you if you want to create a control array. • Click “NO” if you just want a copy of the control. • We will work with control arrays later on.
ListBox and ComboBox Controls • Used to present the end user with choices from a list. • When a list is longer than the list box, scroll bars automatically appear.
Shape Control • Used to add shapes to the form • Square • Circle • Rectangle
CheckBox Control • Used to turn controls on or off. • Indicate the selection of deselection of check boxes on a form.
Frame Control • Used as a container for other controls, such as option buttons. • A frame can only have a rectangle shape. • A frame can have a caption. • When option buttons are added to the frame, only one can be selected at a time.
Option Button Control • Presents a set of choices. • Placed in groups, such as on a frame control. • Must be drawn directly on the frame to be a part of the group.
CommonDialog Control • Allows you to add the Open, Save As, Color, Print and Font commands. • Not visible during run time. • Activate the CommonDialog control by using one of the Show methods.
Aligning Controls • Used to align controls in the form. • Vertically • Horizontally • Format menu
Naming Controls • The name of a control is a property of a control. • Helps the programmer know what control he/she is working with when writing code. • Table 2-2
Writing Code Project 2
Changing Control Properties • Basic Format • controlname.property = value
Variables • Temporary storage locations. • Each variable has a • Name • Data Type – determines the type of data the variable can hold.
Variables cont……….. • Must follow these rules when choosing names for variables. • The name must begin with a letter. • The name cannot be more than 255 characters. • Then name cannot contain punctuation or blank spaces.
Declaring Variables • You must declare, or create, a variable. • This will be done by Explicitly Declaring them. • Dim variablename As datatype • There can be a wide variety of different data types • Byte, date, string, integer, variant, double
Assigning values to a variable • Variables can hold one value at a time. • We use assignment statements to give variables a value. • dblRate = 10.5 • strName = “Mr. Preheim”
Variable Scope • Refers to whether or not the variable is visible to other sub routines. • Variables declared in a sub routine are not visible by other sub routines in the program. • Variables declared in the General Declarations are visible to all subroutines for that form.
Arithmetic Expressions • Code that contains statements to perform mathematical operations. • Order of Precedence – the order in which the calculation will take place. • Can change the order of precedence by using parentheses. • Refer to table 2-7
Arithmetic Expression Examples • dblPayRate = dblHours * curWage • dblTotal = intNumber1 + 100
If..Then…Else Statements • Used to execute one statement or another based on whether a condition is True or False. • A condition is made up of a 2 expressions and a comparison operator. • =, <, >, <=, >=, <>
Key words in an If…Then…Else Statement • If • Then • Else • End If
If Statement Structure • If condition ThenBlock of code if the condition is TrueElseBlock of code if the condition is FalseEnd If
If Structure Flowchart Example Is Matinee Check Box Checked F T Price = 5 Price = 3.5
If Structure VB Code Example • If chkMatinne.Value = 1 Then Price = 3.5Else Price = 5End IF
Constants • Similar to a variable in the idea that it uses space in memory. • However, the value of a constant does not change. • Defined by using the Const statement in the General Declarations.
Concatenation • The process of adding strings together is called concatenation. • Performed by using the ampersand (&) character. Example: textRecord.Text = num & “ ” & cboShow.Text & vbNewLine & txtRecord.Text
Items in a ComboBox • When items are added to a ComboBox, they are assigned an Index number. • The first item is assigned an index of 0. • When an item is selected from the list during runtime, that index number is assigned to the ListIndex property.
Writing Code for the Common Dialog Control • To display the Color dialog box, you will apply the ShowColor method.