0 Replies - 1560 Views - Last Post: 11 June 2008 - 03:17 AM Rate Topic: -----

#1 lodhe1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-June 08

i have problem counter a words in txt file in VBA

Post icon  Posted 11 June 2008 - 03:17 AM

Hi all i need a program to do the following in command button i did but it is not working properly.
my code as follow
Public FileName As String

Private Sub CommandButton1_Click()
Dim c As String
Dim FileName As String
Dim word As String
'Dim c As String
Dim i As Integer
Dim FileNo As String
Dim w() As Characters
 i = 1
c = FreeFile
	Open FileName For Input As #1

	Do While Not EOFİ
	word = ""
	c = Input(1, #1)
	If c <> Empty Then
	word = word + c
	ElseIf Len(word) <> 0 Then
	w(i) = word
	i = i + 1
	word = Empty
	End If
	MsgBox word
	Close #1
End Sub
  Public Sub Open_File()
	FileName = "c:\in.txt"
  End Sub

thanks in advance
One file of unknown length has in each line some words. The number
of words may be different in each line and blank (empty) lines are
allowed. Words may be separated, preceded, and followed, by any
number of spaces. The input file contains spaces and only
alphabetic and numeric characters. It is known in advance that the
number of different words is 100.
Write a VBA program to count the number of each word, it saves in
an output file the result of this count, sorted by the number of
occurrences in decreasing order. When the number of occurrences
is the same for some words, the order of those words is not important.
Optional: if the number of occurrences of some words is the same,
sort them in alphabetical order.

Sample output:

a: 28
at: 11
is: 7
for: 6
the: 6
number: 5
before: 3
count: 2
same: 2
some: 2
very: 2

Is This A Good Question/Topic? 0
  • +

Page 1 of 1