1 / 18

Chapter 6

Chapter 6. Looping Structures. Do…Loop Statement. Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 The Loop While operates the statement at least once Do While intx < 10 intx=intx + 1 Loop. Infinite Loops. May have problems with loops Logic error

abram
Télécharger la présentation

Chapter 6

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. Chapter 6 Looping Structures

  2. Do…Loop Statement • Can operate statements repetitively Do intx=intx + 1 Loop While intx < 10 • The Loop While operates the statement at least once Do While intx < 10 intx=intx + 1 Loop

  3. Infinite Loops • May have problems with loops • Logic error • Overflow error • Infinite Loop

  4. Input Box • Pop-up text box that allows the user to input information • Has a prompt, text box, OK and cancel button • How to display: strx = InputBox(“prompt”, “title”) intx = val(strx) me.lbl.text = intx • If text box is blank = nothing

  5. Accumulator Variables • Variable that stores an accumulating score • Keeps a running total or sum • Just like a counter intTotal = intTotal + intScore • Keep in mind if you’re adding decimals or integers

  6. Flags or Sentinels • Something significant in your program that stops program execution or ends a loop • Generally declared as a constant • Inputbox(“Enter a positive number (-1 to finish)”)

  7. For…Next Statement • Looping structure that performs a set number of times • Operates until a counter reaches an ending value

  8. String Class • The string data type is a class containing multiple properties • String class properties:

  9. String Class Example: • Think of a String as a row of numbered boxes. The first boxe’s number is zero and they go up from left to right. Only one letter can be in each box. 0 1 2 3 4 5

  10. String Methods • Methods are procedures within a class .ToUpper .ToLower .Trim .TrimEnd .TrimStart .PadLeft(length,”char”) .PadRight(length, “char”)

  11. String Substring • These return a portion of the string .Substring(startPos, numOfChars) .Remove(startPos, numOfChars) .Replace(oldString, newString) .Insert(startPos, substring) .IndexOf(substring)

  12. String Class Examples Dim strSeason As String = “SummerTime” Dim strNewString As String strNewString = strSeason.ToUpper ‘SUMMERTIME strNewString = strSeason.ToLower ‘summertime strSeason = “ SummerTime “ strNewString = strSeason.Trim ‘SummerTime strNewString = strSeason.TrimEnd ‘ SummerTime strNewString = strSeason.TrimStart ‘SummerTime

  13. Examples Cont… strSeason = “SummerTime” strNewString = strSeason.PadLeft(15, ”x”) ‘xxxxxSummerTime strNewString = strSeason.PadLeft(9, “x”) ‘SummerTime strNewString = strSeason.PadRight(13, “x”) ‘SummerTimexxx

  14. Examples Cont… Dim strSeason As String = “SummerTime” Dim strNewString As String Dim intPos As Integer strNewString = strSeason.Substring(6,4) ‘Time strNewString = strSeason.Remove(0,6) ‘Time strNewString = strSeason.Replace(“Time”, “ is fun!”) ‘Summer is Fun strNewString = strSeason.Insert(6, “ is a fun “) ‘Summer is a fun Time intPos = strSeason.IndexOf(“mer”) ‘3

  15. String Concatenation • Join two or more strings together • String.concat(string1, string2) • The & operator also joins strings • To add spaces use empty quotes or Space(#) • The Space function will add a stated number of spaces • vbTab adds 8 spaces, vbCrLf - returns

  16. Char Structure • A structure is a simple form of a class • Like the class, a structure has properties chr1 = char.ToUpper(chr2) chr3 = char.ToLower(chr2)

  17. Comparing Strings • Used to alphabetize a list • Compare(string1,string2,Case-insensitive) • Case-insensitive should be true or false • True-case is not considered, a, A • 0-string1 and string 2 equal • 1-string1 is after string2 • -1-string1 is before string2

  18. Like Operator • The Like is used as a Boolean expression • String1 Like String2 • True if String1 matches the pattern of String2 • False if there is no match • ? Used for a single character • * used for many characters • # used for a single number • [] used to enclose a list of characters • used to indicate a range of characters in a character list • , used to separate characters in a character list

More Related