CSC 162 - PowerPoint PPT Presentation

1 / 9
About This Presentation
Title:

CSC 162

Description:

Title: CIS 121 Author: occ Last modified by: Joan & Larry Page Created Date: 9/4/2003 8:50:43 PM Document presentation format: On-screen Show Company – PowerPoint PPT presentation

Number of Views:42
Avg rating:3.0/5.0
Slides: 10
Provided by: OCC81
Category:
Tags: csc | hypotenuse

less

Transcript and Presenter's Notes

Title: CSC 162


1
CSC 162
  • Visual Basic I Programming

2
ListBox Object
  • Unlike a TextBox, a ListBox can hold multiple
    items.
  • Each item gets its own line.
  • Once the ListBox is full, it will automatically
    provide scroll bars to view all the contents.
  • A ListBox cannot be edited directly by the user.
  • A ListBoxs naming convention prefix is lst.
  • To add an item to a ListBox, use the .AddItem
    method
  • lstNames.AddItem(strLastName ", "
    strFirstName)
  • Use the ListBox for outputting the Pythagorean
    Triples, since using Print runs the output off
    the form.

3
Procedures
  • Event procedures
  • respond to an event (mouse click, button press,
    etc.)
  • Visual Basic procedures
  • built-in procedures that perform common tasks
    (MsgBox, InputBox, etc.)
  • Sub procedures
  • programmer-defined procedures that perform tasks
  • Function procedures
  • programmer-defined procedures that perform
    calculations and return values through the
    Functions name

4
Programmer-defined Procedures
  • May have a private or public scope.
  • Scope refers to the region in which the
    identifier can be referenced
  • An identifier with private scope may only be
    referenced from within the current module
  • An identifier with public scope may be referenced
    from anywhere within the current project

5
ByVal or ByRef
  • Procedures can be passed values (called
    parameters) from the calling object.
  • The parameter can either be passed by value
    (ByVal) or by reference (ByRef).
  • ByVal makes a copy of the value being passed,
    thus preserving the original value in the calling
    objects variable
  • ByRef directly access the data in the calling
    objects variable, thus allowing it to be modified

6
Sub Procedure Example (ByVal)
  • Private Sub PrintSquare(ByVal intNum As Integer)
  • intNum intNum 2
  • Print intNum
  • End Sub
  • Private Sub cmdPrint_Click()
  • ' Local variables
  • Dim intValue As Integer
  • ' Get User Data
  • intValue Val(txtNumber.Text)
  • ' Print Initial Value
  • Print intValue
  • ' Call to Sub Procedure
  • Call PrintSquare(intValue)
  • ' Print Final Value

Output (Given 5 in txtNumber) 5 25 5
7
Sub Procedure Example (ByRef)
  • Private Sub PrintSquare(ByRef intNum As Integer)
  • intNum intNum 2
  • Print intNum
  • End Sub
  • Private Sub cmdPrint_Click()
  • ' Local variables
  • Dim intValue As Integer
  • ' Get User Data
  • intValue Val(txtNumber.Text)
  • ' Print Initial Value
  • Print intValue
  • ' Call to Sub Procedure
  • Call PrintSquare(intValue)
  • ' Print Final Value

Output (Given 5 in txtNumber) 5 25 25
8
Function Procedure Example
  • Private Function Area(ByVal intLength As Integer,
    ByVal intWidth As Integer) As Integer
  • ' Local variables
  • Dim intA As Integer ' Local variable for the
    Area
  • intA intLength intWidth
  • Area intA ' Return final value
  • End Function
  • Private Sub cmdFindArea_Click()
  • ' Local variables
  • Dim intL As Integer ' User's entered length
  • Dim intW As Integer ' User's entered width
  • ' Get User Data
  • intL Val(txtLength.Text)
  • intW Val(txtWidthr.Text)
  • ' Print Area

9
Homework
  • Read Chapter 6.1 6.8

Lab Assignment
Read in two legs of a right triangle from the
user in TextBoxes. Compute the hypotenuse using
the Pythagorean Theorem. Return the value in a
Label. To compute the hypotenuse, create a
function called Pythag that takes two Singles as
input and returns its answer as a Single.
Write a Comment
User Comments (0)
About PowerShow.com