1 / 17

The Key Elements of Programs

The Key Elements of Programs. Input/Output How a program communicates with the user. Logic The order in which activities are carried out. Data Storage Manipulation. Word Count Interface. The Count Button. What are the data requirements of the Count button? Constants Input and Results

raquels
Download Presentation

The Key Elements of Programs

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. The Key Elements of Programs • Input/Output • How a program communicates with the user. Logic • The order in which activities are carried out. Data • Storage • Manipulation

  2. Word Count Interface

  3. The Count Button What are the data requirements of the Count button? Constants Input and Results Processing controls

  4. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText As String, thisChar As Char ' a flag Dim scanningWord As Boolean ' a counter and an accumulator Dim c, words As Integer ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  5. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText As String, thisChar As Char ' a flag Dim scanningWord As Boolean ' a counter and an accumulator Dim c, words As Integer ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  6. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText As String, thisChar As Char ' a flag Dim scanningWord As Boolean ' a counter and an accumulator Dim c, words As Integer ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  7. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText As String, thisChar As Char ' a flag Dim scanningWord As Boolean ' a counter and an accumulator Dim c, words As Integer ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  8. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText As String, thisChar As Char ' a flag Dim scanningWord As Boolean ' a counter and an accumulator Dim c, words As Integer ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  9. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText AsString, thisChar AsChar ' a flag Dim scanningWord As Boolean ' a counter and an accumulator Dim c, words As Integer ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  10. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText AsString, thisChar AsChar ' a flag Dim scanningWord As Boolean ' a counter and an accumulator Dim c, words As Integer ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  11. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText AsString, thisChar AsChar ' a flag Dim scanningWord AsBoolean ' a counter and an accumulator Dim c, words As Integer ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  12. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText AsString, thisChar AsChar ' a flag Dim scanningWord AsBoolean ' a counter and an accumulator Dim c, words As Integer ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  13. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText AsString, thisChar AsChar ' a flag Dim scanningWord AsBoolean ' a counter and an accumulator Dim c, words AsInteger ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  14. PrivateSub btnCount_Click(... ' Declare needed variables ' a String of word ending characters Const punctuation = " ,.?!:;()-" & vbNewLine ' a String variable for the text ' and a Char variable for a character Dim theText AsString, thisChar AsChar ' a flag Dim scanningWord AsBoolean ' a counter and an accumulator Dim c, words AsInteger ' Initialise words = 0 scanningWord = False theText = txtIn.Text EndSub

  15. Logic Develop an algorithm to process the input and create the output.

  16. 'at each position in the string For c = 1 To Len(theText)‏ ' extract the charcater thisChar = Mid(theText, c, 1)‏ 'if it's the first letter of a word If Not scanning_ And InStr(punctuation, thisChar) = 0 Then 'increment the word counter words += 1 'set the scanning flag TRUE scanning = True 'if it's the first character AFTER a word ElseIf scanning_ And InStr(punctuation, thisChar) <> 0 Then 'word ended ... no longer scanning word scanning = False 'otherwise move on to the next position End If Next 'display the value in the accumulator lblCount.Text = words

  17. 'at each position in the string For c = 1 To Len(theText)‏ ' extract the charcater thisChar = Mid(theText, c, 1)‏ 'if it's the first letter of a word IfNot scanning_ And InStr(punctuation, thisChar) = 0 Then 'increment the word counter words += 1 'set the scanning flag TRUE scanning = True 'if it's the first character AFTER a word ElseIf scanning_ And InStr(punctuation, thisChar) <> 0 Then 'word ended ... no longer scanning word scanning = False 'otherwise move on to the next position EndIf Next 'display the value in the accumulator lblCount.Text = words

More Related