Page 178 - Open Soource Technologies 304.indd
P. 178

Event Driven Programming



                              ‘Examine and tally each letter of the sentence
                            sentence = (txtSentence.Text).ToUpper
                            For letterNum As Integer = 1 To sentence.Length
                              letter = sentence.Substring(letterNum - 1, 1)
                              If (letter >= “A”) And (letter <= “Z”) Then
                                index = Asc(letter) - 65  ‘The ANSI value of “A”is 65
                                charCount(index) += 1
                              End If
                            Next
                            ‘List the tally for each letter of alphabet
                            lstCount.Items.Clear()
                            For i As Integer = 0 To 25
                              letter = Chr(i + 65)
                              If charCount(i) > 0 Then
                                lstCount.Items.Add(letter  & “  “  & charCount(i))
                              End If
                            Next
                          End Sub

                          [Run, type a sentence into the text box, and press the button.]





































                          172                    LOVELY PROFESSIONAL UNIVERSITY
   173   174   175   176   177   178   179   180   181   182   183