Imports System.IO Public Class Form1 Inherits System.Windows.Forms.Form #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 Label1 As System.Windows.Forms.Label Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents lstA As System.Windows.Forms.ListBox Friend WithEvents lstB As System.Windows.Forms.ListBox Friend WithEvents lstOut As System.Windows.Forms.ListBox Friend WithEvents cmdOpen As System.Windows.Forms.Button Friend WithEvents cmdSave As System.Windows.Forms.Button Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog Friend WithEvents SaveFileDialog1 As System.Windows.Forms.SaveFileDialog Private Sub InitializeComponent() Me.lstA = New System.Windows.Forms.ListBox Me.lstB = New System.Windows.Forms.ListBox Me.lstOut = New System.Windows.Forms.ListBox Me.Label1 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.cmdOpen = New System.Windows.Forms.Button Me.cmdSave = New System.Windows.Forms.Button Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog Me.SaveFileDialog1 = New System.Windows.Forms.SaveFileDialog Me.SuspendLayout() ' 'lstA ' Me.lstA.Location = New System.Drawing.Point(16, 48) Me.lstA.Name = "lstA" Me.lstA.Size = New System.Drawing.Size(96, 160) Me.lstA.TabIndex = 0 ' 'lstB ' Me.lstB.Location = New System.Drawing.Point(144, 48) Me.lstB.Name = "lstB" Me.lstB.Size = New System.Drawing.Size(96, 160) Me.lstB.TabIndex = 1 ' 'lstOut ' Me.lstOut.Location = New System.Drawing.Point(272, 48) Me.lstOut.Name = "lstOut" Me.lstOut.Size = New System.Drawing.Size(96, 160) Me.lstOut.TabIndex = 2 ' 'Label1 ' Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label1.Location = New System.Drawing.Point(16, 24) Me.Label1.Name = "Label1" Me.Label1.TabIndex = 3 Me.Label1.Text = "A Letter Words" ' 'Label2 ' Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.Location = New System.Drawing.Point(144, 24) Me.Label2.Name = "Label2" Me.Label2.TabIndex = 4 Me.Label2.Text = "B Letter Words" ' 'Label3 ' Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.Location = New System.Drawing.Point(272, 24) Me.Label3.Name = "Label3" Me.Label3.TabIndex = 5 Me.Label3.Text = "Output Listbox" ' 'cmdOpen ' Me.cmdOpen.Location = New System.Drawing.Point(24, 232) Me.cmdOpen.Name = "cmdOpen" Me.cmdOpen.TabIndex = 6 Me.cmdOpen.Text = "&Open" ' 'cmdSave ' Me.cmdSave.Location = New System.Drawing.Point(288, 232) Me.cmdSave.Name = "cmdSave" Me.cmdSave.TabIndex = 7 Me.cmdSave.Text = "&Save" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(400, 286) Me.Controls.Add(Me.cmdSave) Me.Controls.Add(Me.cmdOpen) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label1) Me.Controls.Add(Me.lstOut) Me.Controls.Add(Me.lstB) Me.Controls.Add(Me.lstA) Me.Name = "Form1" Me.Text = "Application 1" 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 .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 LineIn = oRead.ReadLine() If InStr(LineIn.ToLower, "a") = 1 Then lstA.Items.Add(LineIn) Else If InStr(LineIn.ToLower, "b") = 1 Then lstB.Items.Add(LineIn) End If End If End While oRead.Close() Else MessageBox.Show("Please Select a File", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End If End With End Sub Private Sub lstA_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstA.Click If lstA.SelectedIndex = -1 Then Exit Sub End If lstOut.Items.Add(lstA.SelectedItem) lstA.Items.RemoveAt(lstA.SelectedIndex) End Sub Private Sub lstB_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstB.DoubleClick If lstB.SelectedIndex = -1 Then Exit Sub End If lstOut.Items.Add(lstB.SelectedItem) lstB.Items.RemoveAt(lstB.SelectedIndex) End Sub Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click Dim i As Integer Dim LineOut As String If lstOut.Items.Count = 0 Then MessageBox.Show("Error the output box is empty!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) Exit Sub End If 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 lstOut.Items.Count - 1 oWrite.WriteLine(lstOut.Items(i)) Next oWrite.Close() Else MessageBox.Show("Please Select a File", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation) End If End With End Sub End Class