Visual programming Graphical User Interface GUI GUI programs

  • Slides: 25
Download presentation
Visual programming

Visual programming

Graphical User Interface (GUI) • GUI programs employ objects such as windows, icons, and

Graphical User Interface (GUI) • GUI programs employ objects such as windows, icons, and menus that can be manipulated by a mouse. • Non-GUI-based programs use only text and are accessed via a keyboard.

Visual basic application • Visual basic programs display a windows style screen (called form)

Visual basic application • Visual basic programs display a windows style screen (called form) with boxes into which users type information and buttons that they click on to initiate actions. The boxes and buttons are referred to as controls.

 • A key element of planning a GUI programs is deciding what user

• A key element of planning a GUI programs is deciding what user sees (design the user interface). • What data will user be entering, how large a window should the program use, where will you place the buttons, will the program have places to enter text (text boxes) and place to display output.

Visual basic IDE

Visual basic IDE

Label control • A Label typically contains descriptive text. • Displays text on the

Label control • A Label typically contains descriptive text. • Displays text on the screen that isn’t editable by the user.

Text. Box • A Text. Box is an area in which a program can

Text. Box • A Text. Box is an area in which a program can display text or the user can type text via the keyboard. • Text. Boxes are typically used to obtain information from the app’s user. • Accepts basic text input from the user.

Button • A Button is a control the user clicks to trigger a specific

Button • A Button is a control the user clicks to trigger a specific action in the program. • Causes the application to perform a predefined task.

Event • Event is an action taken by the user, such as clicking a

Event • Event is an action taken by the user, such as clicking a control or pressing a key. • The program reacts to an event by performing certain tasks.

Example

Example

Code Private Sub add. Button_Click(sender As Object, e As Event. Args) Handles add. Button.

Code Private Sub add. Button_Click(sender As Object, e As Event. Args) Handles add. Button. Click Dim number 1 As Integer ' first number entered by the user Dim number 2 As Integer ' second number entered by the user Dim total As Integer ' sum of the two integers

number 1 = number 1 Text. Box. Text ' get the first number 2

number 1 = number 1 Text. Box. Text ' get the first number 2 = number 2 Text. Box. Text ' get the second number total = number 1 + number 2 ' add the two numbers result. Label. Text = "The sum is " & total ' display the total End Sub ' add. Button_Click End Class ' Addition

Control Structures • Normally, statements in an app are executed one after another in

Control Structures • Normally, statements in an app are executed one after another in the order in which they’re written. This is called sequential execution. • A transfer of control occurs when an executed statement does not directly follow the previously executed statement.

 • all programs could be written in terms of only three types of

• all programs could be written in terms of only three types of control structures: • sequence structure. • selection structure. • repetition structure.

If…Then Selection Statement • A selection statement chooses among alternative courses of action. Suppose

If…Then Selection Statement • A selection statement chooses among alternative courses of action. Suppose that the passing grade on an examination is 60 (out of 100). Then the pseudocode statement If student’s grade is greater than or equal to 60 then Display “Passed”

If student. Grade >= 60 Then result. Label. Text = "Passed" ' display "Passed"

If student. Grade >= 60 Then result. Label. Text = "Passed" ' display "Passed" End If or If student. Grade >= 60 Then result. Label. Text = "Passed"

If…Then…Else Selection Statement • The If…Then…Else selection statement allows you to specify that a

If…Then…Else Selection Statement • The If…Then…Else selection statement allows you to specify that a different action (or sequence of actions) is to be performed when the condition is true than when the condition is false.

If student’s grade is greater than or equal to 60 then Display “Passed” Else

If student’s grade is greater than or equal to 60 then Display “Passed” Else Display “Failed”

code If student. Grade >= 60 Then result. Label. Text = "Passed" ’ display

code If student. Grade >= 60 Then result. Label. Text = "Passed" ’ display "Passed" Else result. Label. Text = "Failed" ’ display "Failed" End If

Nested If…Then…Else Selection Statements • Nested If…Then…Else statements test for multiple conditions by placing

Nested If…Then…Else Selection Statements • Nested If…Then…Else statements test for multiple conditions by placing If…Then…Else statements inside other If…Then…Else statements. • Next example, displays “A” for exam grades greater than or equal to 90, “B” for grades in the range 80– 89, “C” for grades in the range 70– 79, “D” for grades in the range 60– 69 and “F” for all other grades.

If student’s grade is greater than or equal to 90 then Display “A” Else

If student’s grade is greater than or equal to 90 then Display “A” Else If student’s grade is greater than or equal to 80 then Display “B” Else If student’s grade is greater than or equal to 70 then Display “C” Else If student’s grade is greater than or equal to 60 then Display “D” Else Display “F”

If student. Grade >= 90 Then result. Label. Text = "A" ' display "A"

If student. Grade >= 90 Then result. Label. Text = "A" ' display "A" Else If student. Grade >= 80 Then result. Label. Text = "B" ' display "B" Else If student. Grade >= 70 Then result. Label. Text = "C" ' display "C" Else If student. Grade >= 60 The result. Label. Text = "D" ' display "D" Else result. Label. Text = "F" ' display "F" End If

Else. If • Most programmers prefer to write the nested If…Then…Else statements using the

Else. If • Most programmers prefer to write the nested If…Then…Else statements using the Else. If keyword as. Both forms are equivalent, but the latter is popular because it avoids deeply indenting the code and makes it more readable.

If grade >= 90 Then result. Label. Text = "A" ' display "A" Else.

If grade >= 90 Then result. Label. Text = "A" ' display "A" Else. If grade >= 80 Then result. Label. Text = "B" ' display "B" Else. If grade >= 70 Then result. Label. Text = "C" ' display "C“ Else. If grade >= 60 Then result. Label. Text = "D" ' display "D" Else result. Label. Text = "F" ' display "F“ End If