Imports System.IO Module CountTypes ' store strings and counts as hash table ' key = string itself ' value = number of times seen Dim table As New Hashtable ' add strings to hash table Sub Absorb(ByRef sr As StreamReader) Dim line As String While Not sr.EndOfStream line = sr.ReadLine() If line <> "" Then If table.Contains(line) Then table.Item(line) += 1 Else table.Add(line, 1) End If End If End While End Sub ' main program Sub Main(ByVal Args() As String) ' check for command line arguments If Args.Length > 0 Then ' yes, treat them as files For i As Integer = 0 To Args.Length - 1 Dim sr As StreamReader = New StreamReader(Args(i)) Absorb(sr) sr.Close() Next Else ' no, read the standard input Dim sr As StreamReader = New StreamReader(Console.OpenStandardInput) Absorb(sr) sr.Close() End If ' dump the contents of the hash table Dim de As DictionaryEntry For Each de In table Console.WriteLine(de.Value & vbTab & de.Key) Next End Sub End Module