home *** CD-ROM | disk | FTP | other *** search
/ Programming Tool Box / SIMS_2.iso / vb_code2 / str_plus / wordcnt.frm < prev   
Text File  |  1994-07-19  |  4KB  |  122 lines

  1. VERSION 2.00
  2. Begin Form WordCnt 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Word Count"
  6.    ClientHeight    =   4455
  7.    ClientLeft      =   1095
  8.    ClientTop       =   1485
  9.    ClientWidth     =   7365
  10.    ControlBox      =   0   'False
  11.    Height          =   4860
  12.    Left            =   1035
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   4455
  17.    ScaleWidth      =   7365
  18.    Top             =   1140
  19.    Width           =   7485
  20.    Begin CommandButton Command2 
  21.       BackColor       =   &H00C0C0C0&
  22.       Cancel          =   -1  'True
  23.       Caption         =   "O &K A Y"
  24.       Height          =   375
  25.       Left            =   3720
  26.       TabIndex        =   2
  27.       TabStop         =   0   'False
  28.       Top             =   3840
  29.       Width           =   3255
  30.    End
  31.    Begin CommandButton CmdCountWords 
  32.       BackColor       =   &H00C0C0C0&
  33.       Caption         =   "&Count Words"
  34.       Height          =   375
  35.       Left            =   480
  36.       TabIndex        =   1
  37.       TabStop         =   0   'False
  38.       Top             =   3840
  39.       Width           =   3255
  40.    End
  41.    Begin TextBox Text1 
  42.       BackColor       =   &H00FFFF00&
  43.       Height          =   3015
  44.       Left            =   480
  45.       MultiLine       =   -1  'True
  46.       ScrollBars      =   2  'Vertical
  47.       TabIndex        =   0
  48.       Top             =   600
  49.       Width           =   6495
  50.    End
  51.    Begin Label Label1 
  52.       Alignment       =   2  'Center
  53.       BackStyle       =   0  'Transparent
  54.       Caption         =   "Type some text and then press Count Words (works with selected text too):"
  55.       ForeColor       =   &H00000080&
  56.       Height          =   255
  57.       Left            =   480
  58.       TabIndex        =   3
  59.       Top             =   240
  60.       Width           =   6495
  61.    End
  62. End
  63.  
  64. Sub CmdCountWords_Click ()
  65.     'count speed (slow end) is 1800 words/sec on a 386-DX/33
  66.     Screen.MousePointer = 11
  67.     TotalWords% = 0
  68.     nl$ = Chr$(13) + Chr$(10)
  69.     If Text1.SelText = "" Then
  70.         Word$ = Text1.Text      'if NO text highlighted
  71.         CountType$ = "TOTAL"
  72.         Else
  73.         Word$ = Text1.SelText   'if text highlighted
  74.         CountType$ = "SELECTED"
  75.         End If
  76.     If Len(Word$) = 0 Then
  77.         TotalWords% = 0
  78.         GoTo WCdone
  79.         End If
  80.     If InStr(Word$, nl$) = 0 Then
  81.         TotalWords% = CountWords(Word$)
  82.         GoTo WCdone
  83.         End If
  84.    Word$ = Trim$(Word$) + nl$
  85.    Do While Len(Word$) > 0
  86.         OldPos% = InStr(Word$, nl$)
  87.         If OldPos% = 0 Then Exit Do
  88.         TempWord$ = Mid$(Word$, 1, OldPos% - 1)
  89.         x% = CountWords(TempWord$)
  90.         TotalWords% = TotalWords% + x%
  91.         Word$ = Mid$(Word$, OldPos% + 2, Len(Word$) - OldPos% + 2)
  92.         Loop
  93. WCdone:
  94.     Screen.MousePointer = 0
  95.     msg$ = "The " + CountType$ + " word count is:  " + Format$(TotalWords%, "###,##0")
  96.     MsgBox msg$, 64, "Word Count Test"
  97.     Text1.SetFocus
  98. End Sub
  99.  
  100. Sub Command2_Click ()
  101.     Unload Me
  102. End Sub
  103.  
  104. Sub Form_Load ()
  105.     'use this as a speed/accuracy test for long strings
  106.     'test$ = ""
  107.     'nl$ = Chr$(13) + Chr$(10)
  108.     'k$ = "Now is the time for all good men to come to the aid of their country." + nl$
  109.     'For x = 1 To 450: test$ = test$ + k$: Next
  110.     'Text1.Text = test$
  111.  
  112.     FormCenterScreen Me
  113.     Screen.MousePointer = 0
  114. End Sub
  115.  
  116. Sub Form_Paint ()
  117.     DoForm3D Me, sunken, 3, 0
  118.     DoForm3D Me, raised, 1, 3
  119.     DoControl3D Text1, raised, 2
  120. End Sub
  121.  
  122.