1 / 19

CSI 101 Spring 2009

CSI 101 Spring 2009. Review and Recap of Visual Basic Wednesday, April 29 th. List of Concepts. Variables and Data types Conditional processing Looping Specialized functions Type Conversion String Manipulation File Processing Formatting Date processing. List of Concepts, cont.

kgrissom
Download Presentation

CSI 101 Spring 2009

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSI 101 Spring 2009 Review and Recap of Visual Basic Wednesday, April 29th

  2. List of Concepts • Variables and Data types • Conditional processing • Looping • Specialized functions • Type Conversion • String Manipulation • File Processing • Formatting • Date processing

  3. List of Concepts, cont • Subroutines and functions • Classes and objects • Events and event procedures • Using properties

  4. What you’re good at • Variables and data types • IF statements • Setting up functions (FUNCTION statement) • File processing

  5. What we’ll skip • Classes and objects • Covered pretty well in previous lecture • Type conversion • List in inside front cover of text • Encountered in class examples and homework • Formatting • For aesthetic output, not functionally important

  6. Quick recap - Conditional • SELECT statement • Alternative to IF • Allows large number of alternatives • Condition tested is a VALUE, not a Yes or No response

  7. SELECT example • Check if a string starts with a letter or digit

  8. SELECT example • Check if a string starts with a letter or digit SELECT CASE Left(testString,1) CASE “A” to “Z” MsgBox(“Starts with letter”) CASE “a” to “z” MsgBox(“Starts with letter”) CASE “0” to “9” MsgBox(“Starts with digit”) End Select

  9. Looping Recap • DO or FOR • DO has two conditions • Until or While • Can be placed at beginning (with DO) or end (with Loop) • Do ends with Loop • For ends with Next

  10. For example with array • Calculate the average of the values in an array • Need a running sum • Use Length method on arrays to get count

  11. For example with array - code Dim index As Byte, sum as Integer = 0 For index = 1 to array.length sum += array(index) Next index Dim average As Decimal = sum/array.length

  12. For example with strings • Count number of lowercase letter ‘s’ in a particular string • Need to look at EACH character in the string at a time • Need running count • Use a variable much like an array index to mark where we are in the string

  13. For example with strings - code Dim count As Byte = 0 Dim index As Byte For index = 1 to Len(testString) If Mid(testString,index,1) = “s” then count += 1 End if Next index

  14. String function Recap • Most common ones: • Len(string) – returns number of characters in string • Mid(string,start,len) – returns substring starting at start position and for length of len • Left(string,len) – returns substring which is first len characters of string • Trim(string) – remove leading and trailing blanks

  15. Properties and Dates • Let’s finish last ones with an interesting example: • We’ll read employee records from a file • Assume we already have an employee structure • If date of last raise is greater than 18 months, increase salary by 4% • Place employee name and new salary into text boxes on the form • This is contained in the event procedure for the NEXT button

  16. Needs • Open file OUTSIDE of event procedure • Procedure looks for NEXT employee who requires a raise • Reopening file would start us back at the beginning • Remember to Refresh

  17. Code Example • Code outside of event procedure: • Definition of Employee structure • Key fields: • Name • LastRaise • Salary • Opening file: FileOpen(1, “Employees”)

  18. Code Example, cont • Within procedure: Sub btnNext_Click() Dim inEmp As Employee Dim found As Boolean = False Do until found = True Or EOF(1) FileGet(1,inEmp) If DateDiff(“m”,inEmp.LastRaise, Now()) >= 18 then inEmp.Salary *= .04

  19. Code example, cont. found = True txtName.Text = inEmp.Name txtSalary.Text = CStr(inEmp.Salary) End if Loop ‘Check if not found If found = False then txtName.Text = “DONE” Refresh End Sub

More Related