Shared Flashcard Set

Details

Programming chapters 4 and 5
Chapters 4 and 5
71
Computer Networking
Undergraduate 4
10/07/2014

Additional Computer Networking Flashcards

 


 

Cards

Term
Sequence Structure
Definition
*Program statements executed in the order they appear
Term
If Statement
Definition

* Test for a condition being true or false

* Expression is called a Boolean expression because it evaluates to either true or false. If expression is true, execute statements...otherwise statements are skipped

Term
Select Case
Definition
Tests for various values of an expression
Term
If statement example
Definition

if decSales > 5000

MessageBox.Show("You've earned a bonus!")

End if 

Term
Relational Operator
Definition

*Determines if a specific relationship exists between two values 

>     Greater than

<      Less than  

=      Equal to

<>      Not equal to

>=      greater than or equal to

<=               less than or equal to

Term
Two Meanings to =
Definition

*In a stand alone statement = is interpreted as assignment.

intUserNumber = 45

 

*In a Boolean expression = is interpreted as comparison

If intUserNumber = 45 Then

Term

Function Calls in Expressions 

 

Definition

If CInt(txtInput.Text) < 100 Then

lblMessage.Text = "It is true!"

End If

Term
Boolean Variable As Expression
Definition

If blnQuotaMet Then

lblMessage.Text = "You have met your sales quota"

End if 

 

* Note that since a Boolean variable already evaluates to true or false, an = operator is not required 

Term
If ....then...else
Definition

If expression Then

statements

Else

statments

End if 

 

If decSales > 5000 Then

MessageBox.Show("You've earned a bonus!")

Else 

MessageBox.Show("No bonus")

End If

Term
If..then...elseif
Definition

If it is very cold Then

Wear a coat

Elseif it is chilly then

wear a light jacket

Elseif it is windy then

wear a windbreaker

Elseif it is hot then

wear no jacket 

Term
If...then..elself  Order Matters
Definition
*When a condition is true, the remaining conditions are ignored.
Term
Else
Definition
*The trailing else catches any value that falls through the cracks
Term
Nested If Statements
Definition

*Any type of statement can be used inside an if, including another if statement. If statements within if statements creat a more complex decision structure. 

 

If dblSalary>30000 then 

If intYearsOnJob > 2 Then

lblMessage.Text = "Applicant qualifies."

Else 

lblMessage.Text="Applicant does not qualify."

End if

End if 

Term
Compound expression
Definition

*We can combine two or more Boolean expressions into one. 

 

If intTemperature <40 And strSeason = "Summer" Then

lblMessage.Text = "It is unusually cold."

End if 

 

^^ Logical Operator 

Term
Basic Logical Operators
Definition

*Combines multiple Boolean expressions into a compound expression

*And, or , xor, not 

Term
And operator
Definition
both expressions must be true for overall expression to be true
Term
Or operator
Definition

one or both expression must be true for the overall expression to be true 

 

 

If intTemperature < 20 or intTemperature > 100 then

lblMessage.Text = "Unsafe temperature"

End if 

Term
Xor Operator
Definition

*Exclusive or 

*One but not both expressions must be true for overall expression to be true 

Term
Not operator
Definition

*Takes a Boolean Expression and reverses its logical value

*If the expression is true, the not operator returns false, and if the expression is false, it returns true. 

 

Gives you the opposite 

Term
And
Definition

*Best for checking a value inside a range of numbers 

 

If inx >= 20 ANd intX <=40 Then

lblMessage.Text = "The value is in the acceptable range."

End if 

Term
Or
Definition

*Best for checking if a value is outside a range of numbers

 

If intX <20 Or intX > 40 Then

lblMessage.Text = "The value is outside the acceptable range."

End if 

Term
Precedence of Logical Operators
Definition

From highest to lowest 

1. not 

2. and 

3. or 

4.xor

Term
Comparing Strings
Definition

*relational operators can be used to compare strings and string literals 

 

strName1 = "Mary"

strName2 = "Mark"

If strName1 = strName2 Then

lblMessage.Txt = "Name are the same" 

Else 

lblMessage.Text = "Names are not the same"

End if

Term
Empty String
Definition

If txtInput.Text = String.Empty Then

lblMessage.Text = "Please enter a value" 

Else......

Term
ToUpper and ToLower
Definition

*Converts string to upper or lower case letters 

 

ToUpper

strLastName = txtLastName.Text.ToUpper()

 

ToLower

strBigTown = "NewYork"

strLittleTown = strBigTown.ToLower()

Term
Length of A String
Definition

If txtInput.Text.Length >20 Then

lblMessage.Text = "Please enter no more than 20 characters."

End if 

Term
Removing Leading and Trailing Space
Definition

TrimStart - returns the string with leading spaces removed 

TrimEnd - returns the string with trailing spaces removed

Trim - returns the string with leading and trailing spaces removed 

 

lblMessage1.Text = strGreeting.TrimStart()

Term
SubString
Definition

*Returns a portion of a string 

 

StringExpression.Substring(StartPos)

 

strFullName = "George Washington"

strLastName = strFullName.Substring(7) "Washington"

Term
SubString
Definition

strFullName = "George Washington"

strFirstName= strFullName.Substring (0,6) 

'   George 

Term
IndexOf
Definition

*Searches for a specific string within a string 

*Returns the position of the first occurrence of SearchString within StringExpression, or -1 if SearchString is not found

Term

IndexOf

 

Definition

IndexOfstrFullName = "George Washington"

intPosition = strFullName.IndexOf("Wash,9) 

 
will never a -1 because it's not true
Term
IsNumeric
Definition

strNumber = "567"

If IsNumeric (strNumber) Then 'returns true

 

strNumber = "567abc"

If IsNumeric(strNumber) Then 'returns false 

Term
VB Property vs Method vs Function
Definition

*Property is accessed via the dot operator 

strLastName.Length

 

*Method is accessed via the dot operator 

strLastName.ToLower()

 

*No dot operator when calling a function

IsNumeric (strLastName)

Term
Case Method
Definition

*One of several possible actions is taken, depending on the value of an expression

 

Select Case CInt(txtInput.Text)

Case 1

MessageBox.Show ("Day 1 is Monday")

Case 2

MessageBox.Show("Day 2 is tuesday)

 

OR

 

If CInt(txtInput.Text) = 1 Then

MessageBox.Show ("Day 1 is Monday")

If CInt(txtInput.Text) = 2 Then

MessageBox.Show("Day 2 is tuesday)

Term
When to use select case vs if
Definition

*When you're testing multiple possbile alues of an expression you would use select case

 

If intApplicantAge<16 Then

MessageBox.Show("Applicant is too young"

Elseif strApplicantCounty<> Watuauga" Then

MessageBox.Show("Applicant must live in Watuagua")

Term
TryParse
Definition

*Method converts the string representation of a value to a specific data type. A return value indicates whether the conversion succeeded:

returns true if it was successful

false is failed 

*Type.TryPasre(source, destination)


If Integer.TryParse(txtInput.Text, intNumber) Then

lblResult.Text = "Conversion Successful"

Term
Input validation
Definition

* is the process of inspecting user input to see whether it meets certain rules 

 
Term
Input Box
Definition

*Provides a quick and siple way to ask the user to enter data 

*Should not be used as a primary method of input

 

Dim strUserName As String

strUserName = InputBox("Enter you name")

okay will return value

cancel with return empty string

Term
ListBox
Definition

*Controls displays a list of items and also allows the user to select one or more items from the list.

*Displays a scroll bar when all items cannot be shown

*Use lst prefix when naming a list box

Term
ListBox
Definition

*Items = entries in a list box are stored in a property name

*Collection = items is a special type of property

Term

Items Collection

ListBox.Items.Insert.(Index,Item)

Definition

*Items.Count = returns the number of items

*Items.Add() - adds an item at the end

*Items.Insert() - adds an items at specific position

*Items.Clear() - removes all items

*Items.Remove() removes specificed item

*Items.RemoveAt() removes at specificed index

*Items.Contains() - returns true if the collection contains the specified item, or false is if doesnt

Term
ListBox.SeletedItem
Definition

If lstDogs.SelectedItem = "Boxer" Then

MessageBox.Show("You picked Boxer")

Else MessageBox.Show ("You chose another breed)

End if 

Term
ListBox.SelectedIndex
Definition

If lstDogs.SelectedIndex = -1 Then

MessageBox.Show ("no item is selected")

end if 

Term
Sorted
Definition

*A boolean property

*When set to true values in the item property are displayed in aplhabetical order

*When set to false, values in the items property are displayed in the order they were added

*Set to false by default 

Term
Loops
Definition

*Repetition structure or loop causes one or more statements to repeat

*Each reprtition of the loop is = iteration

 

Three types:

1.do while

2.do until

3.for next

Term
Do while loop
Definition

**A boolean expression that is tested for a true or false value

*a statement or group of statements that is repeated as long as the boolean expression is true 

 

Dim intCount As Integer = 0

Do While intCount <10

lstOutput.Items.Add ("Hello")

intCount += 1

Loop

 

Term
Infinte Loops
Definition

*A loop must have some way to end itself

*If the test expression can never be false, the loop will continue to repeart forever

Term
Counters
Definition

*A variable that is incremented or decremented in each loop interation

* Increment means add 1

*Decrement means to subtract 1

Term
Do Until Loop
Definition

*Iterates until the expression is true

 

Term
Pretest
Definition

* Loop the expression is tested before the body is executed

 

Do While intCount<10

lstOutput.Items.Add("hello")

intCount += 1

Loop

 

Term
Posttest
Definition

*Loop the body is executed before expression is tested 

 

Do

lstOutput.Items.Add("Hello")

intCount += 1

Loop while intCount <10

Term
For Next Loop
Definition

*Ideal for loops that require a counter 

*Pretest form only

 

For intCount = 0 to 9

lstOutput.Items.Add ("Hello")

Next

Term

Step Value 

 

Definition

*Is the value added to the counter variable at the end of each iteration. If not specified it defaultss to 1

 

For inCount = 0 to 100 Step 10

MessageBox.Show(intCount.ToString())

Next

 

counts as 0,10,20,30,40....100

Term
Breaking out of a loop
Definition

*Exit do : used in do while or do until

*Exit for : used in for next loops 

 

caution it can be difficult to debug

 

Dim strInput As String

 

Do Until strInput = "John"

strInput = InputBox("What is the password")

If strInput = " " Then

Exit Do

End If 

Loop 

Term
Which loop?
Definition

*For ..Next = when the number or required iterations is known

*Do while = when you wish the loop to repeat as long as the test expression is true

*Do until = when you wish the loop to repeat as long as the test pression is false 

Term
Nested Loops
Definition

*Loop insidde another loop

 

For intSeconds = 0 to 59

lblSeconds.Text = intSeconds.ToString()

Next 

For intSeconds = 0 to 59

lblSeconds.Text = intSeoncds.ToString()

Term
Muticolumn List Box
Definition

* Boolean property with default alue of false 

*If set to true, entries can appear side by side

 

Term

CheckedListBox

clb

Definition

*Variation of the listbox contril with a checkbox beside each item

*Determines how items may be checked.

False = user clickess item once to select it again to check it

True - user clicks item only once to both selet it and check it 

 

Term
GetItemChecked Example
Definition

Dim intIndex As Integer

For inIndex = 0 To clbToppings.Items.Count - 1

If clbToppings.GetItemChecked (intIndex) Then

MessageBox.Show(clbToppings.Items (intIndex) + " is checked"

End if 

Next

Term
SetItemChecked
Definition

*Method to set the checked state of each item in code. 

 

Dim intIndex As Integer

For intIndex = 0 To clbToppings.Items.Count - 1

clbToppings.SetItemChecked (intIndex, False)

Next 

Term

ComboBox Control

cbo

Definition

*A cobination of a ListBox and a TextBox

*You can allow the user to either choose an item from the list or type in a value 

 

*Simple = visible, editable, type in a value and not limited to selecting what is there

*DropDown = click down arrow, editable

DropDownList = click down arrow, not editable

Term
Random Numbers
Definition

*Random.Net get a random integer nuber in the range minValue to maxValue

 

intNum= rand.Next (0,100) 

Term
With End With
Definition

With textName

.clear()

.ForeColor = Color.Blue

.BackColor = Color.Yellow

End With

Term
Adding ToolTip Control
Definition

*Appears in the compnent tray, not the form

*Resizable region at the bottom of the designer window that holds invisible controls 

 

Term
ToolTip Properties
Definition

*AutoPopDelay = determines how long a tip is displayed

*InitialDelay = regulates the delay before a tip appears

*ReshowDelay = determines the time between the display of different tips as the user moves the mouse from control to control

*AutomaticDelay = sets the above 3 properties alll at once

Term
Pmt
Definition

*Payment returns the periodic payment amount for a loan with a fixed interest rate 

 

dblPayment = Pmt(dblAnnInt / 12, Number of Periods, loan amount which must be negative)

 

3 parts 

Term
IPmt
Definition

*Function returns the interest portion for a specific period of a loan with a fixed interest rate and fixed monthly payment

 

IPmt (PeriodsInterestRate, 12, Number of periods, -loan amount)

 

4 parts 

Term
PPmt
Definition

*Funcion returns the principal portion for a specific period of a loan with a fixed interest rate and fixed monthly payments

dblPrincipal = PPmt (dblAnnInt /12, Number of periods, -loan amount)

 

4 parts 

Term
Using Pmt,IPmt, PPmt
Definition

*The sume of the interest portion and principal portion will equal the total payment :

total payment = (interest portion)+(principal portion)

 

Supporting users have an ad free experience!