home *** CD-ROM | disk | FTP | other *** search
/ An Introduction to Progr…l Basic 6.0 (4th Edition) / An Introduction to Programming using Visual Basic 6.0.iso / PROGRAMS / CH7 / 7-1-7.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-09-18  |  4.2 KB  |  128 lines

  1. VERSION 5.00
  2. Begin VB.Form frm7_1_7 
  3.    Caption         =   "Character Count"
  4.    ClientHeight    =   1905
  5.    ClientLeft      =   1020
  6.    ClientTop       =   2160
  7.    ClientWidth     =   7365
  8.    BeginProperty Font 
  9.       Name            =   "Times New Roman"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   400
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    LinkTopic       =   "Form1"
  18.    PaletteMode     =   1  'UseZOrder
  19.    ScaleHeight     =   1905
  20.    ScaleWidth      =   7365
  21.    Begin VB.PictureBox picLetterCount 
  22.       BeginProperty Font 
  23.          Name            =   "Courier New"
  24.          Size            =   9
  25.          Charset         =   0
  26.          Weight          =   400
  27.          Underline       =   0   'False
  28.          Italic          =   0   'False
  29.          Strikethrough   =   0   'False
  30.       EndProperty
  31.       Height          =   1215
  32.       Left            =   2160
  33.       ScaleHeight     =   1155
  34.       ScaleWidth      =   4995
  35.       TabIndex        =   3
  36.       Top             =   600
  37.       Width           =   5055
  38.    End
  39.    Begin VB.CommandButton cmdAnalyze 
  40.       Caption         =   "Analyze Sentence"
  41.       Default         =   -1  'True
  42.       BeginProperty Font 
  43.          Name            =   "MS Sans Serif"
  44.          Size            =   8.25
  45.          Charset         =   0
  46.          Weight          =   700
  47.          Underline       =   0   'False
  48.          Italic          =   0   'False
  49.          Strikethrough   =   0   'False
  50.       EndProperty
  51.       Height          =   495
  52.       Left            =   120
  53.       TabIndex        =   2
  54.       Top             =   480
  55.       Width           =   1815
  56.    End
  57.    Begin VB.TextBox txtSentence 
  58.       BeginProperty Font 
  59.          Name            =   "MS Sans Serif"
  60.          Size            =   8.25
  61.          Charset         =   0
  62.          Weight          =   700
  63.          Underline       =   0   'False
  64.          Italic          =   0   'False
  65.          Strikethrough   =   0   'False
  66.       EndProperty
  67.       Height          =   285
  68.       Left            =   1200
  69.       TabIndex        =   1
  70.       Top             =   120
  71.       Width           =   6015
  72.    End
  73.    Begin VB.Label lblSentence 
  74.       Alignment       =   1  'Right Justify
  75.       Caption         =   "Sentence"
  76.       BeginProperty Font 
  77.          Name            =   "MS Sans Serif"
  78.          Size            =   8.25
  79.          Charset         =   0
  80.          Weight          =   700
  81.          Underline       =   0   'False
  82.          Italic          =   0   'False
  83.          Strikethrough   =   0   'False
  84.       EndProperty
  85.       Height          =   255
  86.       Left            =   120
  87.       TabIndex        =   0
  88.       Top             =   120
  89.       Width           =   975
  90.    End
  91. Attribute VB_Name = "frm7_1_7"
  92. Attribute VB_GlobalNameSpace = False
  93. Attribute VB_Creatable = False
  94. Attribute VB_PredeclaredId = True
  95. Attribute VB_Exposed = False
  96. Private Sub cmdAnalyze_Click()
  97.   Dim index As Integer, letterNum As Integer, sentence As String
  98.   Dim letter As String, column As Integer
  99.   'Count occurrences of different letters in a sentence
  100.   ReDim charCount(Asc("A") To Asc("Z")) As Integer
  101.   For index = Asc("A") To Asc("Z")
  102.     charCount(index) = 0
  103.   Next index
  104.   'Consider and tally each letter of sentence
  105.   sentence = UCase(txtSentence.Text)
  106.   For letterNum = 1 To Len(sentence)
  107.     letter = Mid(sentence, letterNum, 1)
  108.     If (letter >= "A") And (letter <= "Z") Then
  109.         index = Asc(letter)
  110.         charCount(index) = charCount(index) + 1
  111.     End If
  112.   Next letterNum
  113.   'List the tally for each letter of alphabet
  114.   picLetterCount.Font = "Courier"
  115.   picLetterCount.Cls
  116.   column = 1   'Next column at which to display letter & count
  117.   For letterNum = Asc("A") To Asc("Z")
  118.     letter = Chr(letterNum)
  119.     picLetterCount.Print Tab(column); letter;
  120.     picLetterCount.Print Tab(column + 1); charCount(letterNum);
  121.     column = column + 6
  122.     If column > 42 Then   'only room for 7 sets of data in a line
  123.         picLetterCount.Print
  124.         column = 1
  125.     End If
  126.   Next letterNum
  127. End Sub
  128.