Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Public list As New ArrayList(10)
Public i As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents cmdOpen As System.Windows.Forms.Button
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents Button3 As System.Windows.Forms.Button
Friend WithEvents Button4 As System.Windows.Forms.Button
Friend WithEvents Button5 As System.Windows.Forms.Button
Friend WithEvents Button6 As System.Windows.Forms.Button
Friend WithEvents Button7 As System.Windows.Forms.Button
Friend WithEvents Button8 As System.Windows.Forms.Button
Friend WithEvents Button9 As System.Windows.Forms.Button
Friend WithEvents Button10 As System.Windows.Forms.Button
Friend WithEvents Button11 As System.Windows.Forms.Button
Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.cmdOpen = New System.Windows.Forms.Button
Me.Button1 = New System.Windows.Forms.Button
Me.Button2 = New System.Windows.Forms.Button
Me.Button3 = New System.Windows.Forms.Button
Me.Button4 = New System.Windows.Forms.Button
Me.Button5 = New System.Windows.Forms.Button
Me.Button6 = New System.Windows.Forms.Button
Me.Button7 = New System.Windows.Forms.Button
Me.Button8 = New System.Windows.Forms.Button
Me.Button9 = New System.Windows.Forms.Button
Me.Button10 = New System.Windows.Forms.Button
Me.Button11 = New System.Windows.Forms.Button
Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog
Me.SuspendLayout()
'
'cmdOpen
'
Me.cmdOpen.Location = New System.Drawing.Point(16, 24)
Me.cmdOpen.Name = "cmdOpen"
Me.cmdOpen.Size = New System.Drawing.Size(72, 24)
Me.cmdOpen.TabIndex = 0
Me.cmdOpen.Text = "Open"
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(16, 72)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(72, 24)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(16, 104)
Me.Button2.Name = "Button2"
Me.Button2.Size = New System.Drawing.Size(72, 23)
Me.Button2.TabIndex = 2
Me.Button2.Text = "Button2"
'
'Button3
'
Me.Button3.Location = New System.Drawing.Point(16, 136)
Me.Button3.Name = "Button3"
Me.Button3.Size = New System.Drawing.Size(72, 23)
Me.Button3.TabIndex = 3
Me.Button3.Text = "Button3"
'
'Button4
'
Me.Button4.Location = New System.Drawing.Point(16, 168)
Me.Button4.Name = "Button4"
Me.Button4.Size = New System.Drawing.Size(72, 23)
Me.Button4.TabIndex = 4
Me.Button4.Text = "Button4"
'
'Button5
'
Me.Button5.Location = New System.Drawing.Point(16, 200)
Me.Button5.Name = "Button5"
Me.Button5.Size = New System.Drawing.Size(72, 23)
Me.Button5.TabIndex = 5
Me.Button5.Text = "Button5"
'
'Button6
'
Me.Button6.Location = New System.Drawing.Point(16, 232)
Me.Button6.Name = "Button6"
Me.Button6.Size = New System.Drawing.Size(72, 23)
Me.Button6.TabIndex = 6
Me.Button6.Text = "Button6"
'
'Button7
'
Me.Button7.Location = New System.Drawing.Point(16, 264)
Me.Button7.Name = "Button7"
Me.Button7.Size = New System.Drawing.Size(72, 23)
Me.Button7.TabIndex = 7
Me.Button7.Text = "Button7"
'
'Button8
'
Me.Button8.Location = New System.Drawing.Point(16, 296)
Me.Button8.Name = "Button8"
Me.Button8.Size = New System.Drawing.Size(72, 23)
Me.Button8.TabIndex = 8
Me.Button8.Text = "Button8"
'
'Button9
'
Me.Button9.Location = New System.Drawing.Point(16, 328)
Me.Button9.Name = "Button9"
Me.Button9.Size = New System.Drawing.Size(72, 23)
Me.Button9.TabIndex = 9
Me.Button9.Text = "Button9"
'
'Button10
'
Me.Button10.Location = New System.Drawing.Point(16, 360)
Me.Button10.Name = "Button10"
Me.Button10.Size = New System.Drawing.Size(72, 23)
Me.Button10.TabIndex = 10
Me.Button10.Text = "Button10"
'
'Button11
'
Me.Button11.Location = New System.Drawing.Point(16, 392)
Me.Button11.Name = "Button11"
Me.Button11.Size = New System.Drawing.Size(72, 23)
Me.Button11.TabIndex = 11
Me.Button11.Text = "Button11"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(352, 502)
Me.Controls.Add(Me.Button11)
Me.Controls.Add(Me.Button10)
Me.Controls.Add(Me.Button9)
Me.Controls.Add(Me.Button8)
Me.Controls.Add(Me.Button7)
Me.Controls.Add(Me.Button6)
Me.Controls.Add(Me.Button5)
Me.Controls.Add(Me.Button4)
Me.Controls.Add(Me.Button3)
Me.Controls.Add(Me.Button2)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.cmdOpen)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub cmdOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOpen.Click
Dim oFile As System.IO.File
Dim oRead As System.IO.StreamReader
Dim LineIn As String
With OpenFileDialog1
.Filter = "Text Files (*.txt)|*.txt"
.FilterIndex = 1
.FileName = "Names2.txt"
.Title = "Pick a file to open..."
.CheckFileExists() = True
.CheckPathExists = True
.ValidateNames = True
.DereferenceLinks = True
If .ShowDialog() = DialogResult.OK Then
oRead = oFile.OpenText(.FileName)
While oRead.Peek <> -1
list.Add(oRead.ReadLine())
End While
oRead.Close()
Else
MessageBox.Show("Please Select a File", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End With
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
MessageBox.Show(list.Count)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim count As Integer
For i = 0 To list.Count - 1
If Mid(list(i), 1, 1) = "A" Then
count += 1
End If
Next
MessageBox.Show("There are " & count & " name(s) starting with ""A""")
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim count As Integer
For i = 0 To list.Count - 1
If Mid(list(i), 1, 1) = "E" Then
count += 1
End If
Next
MessageBox.Show("There are " & count & " name(s) starting with ""E""")
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim letter As String = InputBox("Please enter a letter")
Dim count As Integer
For i = 0 To list.Count - 1
If Mid(list(i), 1, 1) = letter Then
count += 1
End If
Next
MessageBox.Show("There are " & count & " name(s) starting with " & letter)
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim name As String = InputBox("Please enter a name")
Dim count As Integer
For i = 0 To list.Count - 1
If list(i) = name Then
count += 1
End If
Next
MessageBox.Show("There are " & count & " " & name & "(s)")
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim letter As String = InputBox("Please enter a letter")
Dim count As Integer
For i = 0 To list.Count - 1
If Mid(list(i), Len(list(i)), 1) = letter Then
count += 1
End If
Next
MessageBox.Show("There are " & count & " names ending in " & letter)
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
Dim letter As String = InputBox("Please enter a letter")
Dim count As Integer
For i = 0 To list.Count - 1
If Mid(list(i), 2, 1) = letter Then
count += 1
End If
Next
MessageBox.Show("There are " & count & " names which second letter is " & letter)
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
Dim count, j As Integer
For i = 0 To list.Count - 1
For j = 1 To Len(list(i))
If Mid(list(i), j, 1) = "a" Then
count += 1
End If
Next
Next
MessageBox.Show("There are " & count & " a's in the file Names2.txt")
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
Dim count, countB, j As Integer
For i = 0 To list.Count - 1
For j = 1 To Len(list(i))
If Mid(list(i), j, 1) = "b" Then
count += 1
End If
If Mid(list(i), j, 1) = "B" Then
countB += 1
End If
Next
Next
MessageBox.Show("There are " & count & " b's" & vbNewLine _
& "There are " & countB & " B's in the file Names2.txt")
End Sub
Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
Dim count, count2, j As Integer
Dim letter As String = InputBox("Please enter a letter").ToLower
For i = 0 To list.Count - 1
If InStr(list(i), letter) > 0 Then
count += 1
End If
If InStr(list(i), letter.ToUpper) > 0 Then
count2 += 1
End If
Next
MessageBox.Show("There are " & count & " names with " & letter.ToLower & vbNewLine _
& "There are " & count2 & " names with " & letter.ToUpper & " in the names2.txt file")
End Sub
Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
Dim savelist As New ArrayList(10)
Dim count, count2, j As Integer
Dim letter As String = InputBox("Please enter a letter").ToLower
For i = 0 To list.Count - 1
If InStr(list(i), letter) > 0 Then
savelist.Add(list(i))
End If
If InStr(list(i), letter.ToUpper) > 0 Then
savelist.Add(list(i))
End If
Next
With SaveFileDialog1
.Filter = "Text Files (*.txt)|*.txt"
.FilterIndex = 1
.Title = "Pick a file to open..."
.CheckPathExists = True
.ValidateNames = True
.DereferenceLinks = True
If .ShowDialog() = DialogResult.OK Then
Dim oWrite As New System.IO.StreamWriter(.FileName)
For i = 0 To savelist.Count - 1
oWrite.WriteLine(savelist(i))
Next
oWrite.Close()
Else
MessageBox.Show("Please Select a File", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End With
End Sub
End Class