170 likes | 206 Views
Learn how a program communicates, the order of activities, data storage & manipulation using Count Button Interface in a programming environment.
E N D
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
The Count Button What are the data requirements of the Count button? Constants Input and Results Processing controls
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
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
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
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
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
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
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
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
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
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
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
Logic Develop an algorithm to process the input and create the output.
'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
'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