Está en la página 1de 3

Introduction to Visual Basic (ITSE 1331) Exam 2 Gaddis/Irvine

Decision Structure • IsNumeric function–an intrinsic function that accepts a string as


• Decision Structure–allows a program to have more than one path its argument, and returns True if the string contains a number; the
of execution. function returns False if the string's contents cannot be
• If…Then Statement–causes other statements to execute only recognized as a number.
under a certain condition. • IndexOf method–searches for a character or a string within a
• If…Then…Else Statement–executes one group of statements if the string. Returns a -1 if the search string is not found.
condition (or Boolean expression is true and another group of • First character in a string–has an index of 0.
statements if the condition is false.) Message Boxes
Example: • MessageBox.Show Method—allows you to display a message in a
If condition Then dialog box.
statement
(more statements may follow)
• Example Syntax: MessageBox(Message, Caption, Buttons, Icon)
This format shows a dialog box with the Message in the center of
Else
the box, a caption in the title bar, a specified button to appear, and
statement
an icon to display in the message box. You do not have to
(more statements may follow)
specify each item past Message if you accept the default.
End If
However, if you want to specify an icon, then you must specify
Notice that there is no condition tested after the Else!
the button type even though the default button is OK because you
Relation Operator
need to specify in order.
• > Greater than Select Case Statement
• < Less than
• = Equal to • Select Case statement–one of several possible actions is taken,
depending on the value of an expression. Tests the value of an
• <> Not equal to
expression once and then uses that value to determine the result.
• >= Greater than or equal to
• <= Less than or equal to • Select Case–the first line of a Select Case statement and is
followed by a test expression. The test expression may be any
• All relational operators are binary, which means they use two
numeric or string expression whose value you wish to test.
operands.
• Relational expression–consists of a relational operator and its • Case Statement–expression list can contain multiple expressions,
separated by commas. For example: Case value = 1, 7, 15 means
operands.
the TestExpression compares to 1, 7, and 15.
• Relational operator used with math operators–the math operators
always execute first.
• End Select–ends the Select Case statement.
Logical Operator • Is keyword–represents the test expression in the relational
comparison in the Case statement.
• And operator–combines two expressions into one. Both
expressions must be true for the overall expression to be true. • Multiple expressions–in a case statement expression list are
separated by commas.
• XOR operator–combines two expressions into one. One Radio Buttons
expression (not both) must be true for the overall expression to be
true. If both expressions are true, or both expressions are false, • Mutually exclusive–because only one radio button in a group can
the overall expression is false. be selected at any given time, they are said to be mutually
Strings exclusive.
Input Boxes
• Unicode–a set of numeric codes that represent all the letters of
the alphabet (both lowercase and uppercase), the printable digits • Input Boxes– provide a simple way to gather input without
0 through, punctuation symbols, and special characters. The placing a text box on a form.
Unicode system is extensive enough to encompass all the world's • Input Box Format—InputBox(Prompt [,Title] [, Default] [, Xpos]
alphabets. Used by Visual Basic.Net. [, Ypos]) The Title, Default, Xpos, Ypos are optional. Example:
• Testing for No Input–when the user has not entered a value into a strUserInput = InputBox("Enter your age.", "Input Needed")
text box; Compare the TextBox control's Text property to the The value the user enters in the input box is stored as a string in
predefined Constant String.Empty or to "" which represents an strUserInput.
empty string. • Input Box CancelButton—returns the number -1 when selected.
• ToUpper method–a string method that returns the string • ListBox–a control that appears as a box containing a list of items.
representation of a variable in all uppercase letters. • ListBox control–displays a list of items and allows the user to
• Trim method–returns a copy of the string without leading or select one or more items from the list. A scroll bar is
trailing spaces. automatically added to the list box when it contains more items
• TrimEnd method–returns a copy of the string without trailing than can be displayed.
spaces. • Items.Add Method–to store values in the Items property with code
• Substring method–returns a substring, or a string within a string. at runtime, use the Items.Add method. The general format:
For example: strPart = fullString.Substring(0,6) returns the 6 ListBox.Items.Add(Item). ListBox is the name of the list box
characters that begin at position 0 in fullString. After the code control. Item is the value to be added to the Items property. The
execution strPart contains the string returned. Item will be added to the end of the list box.
• Items Property–items that are displayed in a list box or combo • Nested Loop – a repeating structure, containing another repeating
box are stored as strings in the Items property. structure. Complete the inner loop before continuing the outer
• Items.Count property–holds the number of items in a list box or loop. Compare to a clock. The second hand completes its loop
combo box. before the minute hand advances.
• First Item in a List Box–has an index of 0. Input Validation
• Sorted property–when set to True will put the items in the list into • Do…While loop–a looping structure that causes one or more
alphabetical order. statements to repeat as long as an expression is true.
• Items.Clear–method will erase all the items in the list box. • Validation–checks for
• CheckBox–a box that is checked or unchecked when clicked with 1. Numbers in a range.
the mouse. 2. Values that might cause problems.
• CheckBox control–allows the user to make yes/no or on/off 3. Items selected from a menu.
selections, may appear alone or in groups. • Validated event – triggered after the Validating event is triggered
• Combo box–a control that is the combination of a ListBox and a and the focus has shifted to another control.
Textbox. • Validating event–before the focus shifts from Control A to
• Combo boxes–similar to list boxes, display lists of items to the Control B, and Control B's CausesValidation property is set to
user. Styles include Drop-Down Combo Box, Simple Combo True, Control A's Validating event will fire.
Box, and Drop-Down List Combo Box. • CausesValidation property–a Boolean property; when the focus is
Loops shifting from Control A to Control B, and Control B's
CausesValidation property is set to True, Control A's
• Loop – a repeating structure, containing a block of code. Validating event will fire.
• Counter – a variable that is regularly incremented or decremented • InitialDelay property–determines the amount of time, in
each time a loop iterates (runs).
milliseconds, that elapses between the user pointing the mouse
• For…Next loop–a pre-test loop specifically designed to first at a control and the tool tip appearing.
initialize, then test, and lastly increment a count variable at the
end of each iteration.
• Counter–a variable that can be incremented or decremented each
time a loop runs.
• Example: Pmt, IPmt, and PPmt Functions
For intCount =1 to 10
statement • Pmt function – returns the periodic payment amount for a loan. It
(more statements may follow) assumes the loan has a fixed interest rate.
Next [intCount]
• IPmt function–returns the interest payment for a specific period
• Step value–the value added to the counter variable at the end of on a loan. It assumes the loan has a fixed interest rate, with
each iteration of a For…Next loop. fixed monthly payments.
• Step increment–part of the statement is optional. If it is present, • PPmt function–returns the principal payment for a specific
Increment must be a numeric expression in the amount added periods on a loan. It assumes the loan has a fixed interest rate,
(or subtracted when negative) to the counter variable at the end with fixed monthly payments.
of each iteration. If the Step Increment part of the statement is ToolTip
omitted, the counter variable is incremented by 1 at the end of
each iteration. • ToolTip–is a control that allows the user to create a small box that
displays when the user places the mouse over the control.
• Do While loop – repeats so long as the expression is true. The Measurements
statements in a do while loop may never execute if the
condition initially evaluates to false. And, the loop may never • Twip–1/1440th of an inch; twips are used as a measurement for
stop if the condition evaluates to true and is never changes positioning input boxes on the screen.
within the loop Sub Procedures and Functions
• Do Until loop–a looping structure that causes one or more • Sub procedure–a collection of statement that performs a task.
statements to repeat until its test expression is true. A pretest Even handlers belong to this category.
loop will not perform a single iteration when the initial test • Using Sub procedures you can:
expression is false. 1. You can modularize an application's code.
1. The Do Until loop may be written in pretest or posttest form. 2. It will make it easier to maintain and modify code.
2. The pretest form is 3. You can write code once, and have it performed in many
Do Until expression places.
statement • General purpose procedures—perform specific tasks. General
(more statements may follow) purpose procedures are not triggered by event, but are called from
Loop statements in other procedures.
3. The posttest form is • Function Procedure–a collection of statements that performs a
Do task and then returns a value to the part of the program that
Statement executed it. Return values can be nonnumeric values, String
(more statements may follow) values, Boolean values, numeric values—any value that is a valid
Loop Until expression data type. Function procedures work like intrinsic functions,
such as CInt and IsNumeric.
• Event handler or event procedure–a type of Sub procedure that is Debugging
executed when an event, such as a mouse click, occurs while the • Break Mode–the mode in which an application has been
program is running. suspended for debugging purposes. In break mode, pressing F8
• General form of a Sub procedure declaration: – will activate the Step Into command.
[AccessSpecifier] Sub ProcedureName ([ParameterList]) • Step Into command–a debugging command that allows you to
[Statements] execute a single programming statement; if the statement contains
End Sub a call to a procedure or function, the next execution point that
• AccessSpecifier–specifies the accessibility of the procedure. If will be displayed in the first line of code in that procedure or
you do NOT provide an access specifier for a Sub Procedure then function. Allows the programmer to execute all of the
it will be Public. procedures/functions in the program.
• Private access specifier–the procedure may only be accessed by Math Warnings!
other procedures declared in the same class or form. If you want • If you are calculating the cost of an item that is marked down
to prevent statements from outside a form (from an accessing 10%, the amount that you save is 10%. The amount that you pay
procedure), set the access specified to Private in the procedure's is 90%. If I ask, what is the discount amount that is the amount
declaration. calculated at 10%. If I ask what is the new discounted price, that
is the price you would pay, or 90% of the original cost.
• Static local variable–variables that are not destroyed when a Sub
procedure or function returns; they exist for the lifetime of the • If you are calculating an average of a list of numbers, add all the
application, even though their scope is only the Sub procedure or numbers up first. Then, divide the total by the count of the list.
function in which they are declared and they retain their values If there are 4 numbers in the list, divide by 4. If there are 20
between procedure calls. If a procedure is called more than once numbers in the list, divide by 20, etc.
in a program, the values stored in the procedure's variables will
persist only if declared with the Static keyword.
• Argument–a value passed to a procedure or function when it is
called. The number of arguments in the call matches the number
of arguments in the procedure and are matched by number, order
and type, not name.
• Parameter–a special variable that receives an argument being
passed into a method, Sub procedure, or function. Dim should
not be used in the parameter variable declaration.
• Call–a keyword that may be optionally used to call a procedure.
A procedure call is simply the name of the procedure that is to be
executed. Parentheses follow the name of the procedure.
• When calling a Sub Procedure, the arguments and the
corresponding parameters must agree: –
1. The order of arguments and parameters must correspond.
2. The type the arguments and parameters must correspond
3. The number of the arguments and the parameters must be the
same.
4. Does not use the Return statement.
• Valid Function Use:
1. Use a function call in an expression.
2. You need to have a return statement in a function.
3. You can assign the return value from a function to a variable.
4. You can return string values, nonnumeric values, Boolean
values, numeric values from a function.
• Pass by value–only a copy of the argument is passed to the
procedure.
• ByVal keyword–indicates that arguments passed into the variable
are passed by value.
• Pass by reference–the procedure has access to the original
argument.
• ByRef keyword–used to declare a parameter variable, causing its
argument to be passed by reference. When an argument is passed
to a procedure this way, the procedure has access to the original
argument and may make changes to it.
• When a Sub procedure has finished executing–the application
branches back to the procedure call, and resumes executing at the
next line. String values, numeric values, and Boolean values can
be returned by a function.

También podría gustarte