Imports System.IO Public Class Form1 Inherits System.Windows.Forms.Form ' Written by Phil Persson on October 25, 2003 ' For System Concepts Incorporated ' 'This program will compare two text files containing file version information and 'will report on differences between the two files. This will aid support analysts 'in determining if a customer workstation has all the correct and up-to-date 'files required by the specified version of FOOD-TRAK software ' 'Version History: ' PBP 10-25-2003 Initial Creation ' PBP 01-02-2004 Modified to check first line of each file - if the first ' line contains blanks or a null, flag as invalid format and ' display error ' PBP 12-05-2004 Modified to display output in data grid to allow for ' varying file names ' PBP 10-15-2005 Modified to allow drag and drop of files for standard and compare ' Adding file menu on top of form, removing some buttons from form ' Adding version history into help menu ' Dim StandardFile As StreamReader Dim Comparefile As StreamReader Dim StandardFileNameOK, CompareFileNameOK As Boolean Dim strStandardFileName, strCompareFileName As String Dim intLargestFileNameLength, intLargestVersionNumberLength 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 Label1 As System.Windows.Forms.Label Friend WithEvents Label3 As System.Windows.Forms.Label Friend WithEvents Label5 As System.Windows.Forms.Label Friend WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents lblStdFileName As System.Windows.Forms.Label Friend WithEvents btnCompare As System.Windows.Forms.Button Friend WithEvents Label2 As System.Windows.Forms.Label Friend WithEvents lblStdRecs As System.Windows.Forms.Label Friend WithEvents Label7 As System.Windows.Forms.Label Friend WithEvents lblCompareRecs As System.Windows.Forms.Label Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog Friend WithEvents lblCompareFileName As System.Windows.Forms.Label Friend WithEvents grpVertical As System.Windows.Forms.GroupBox Friend WithEvents grpHorizontal As System.Windows.Forms.GroupBox Friend WithEvents dtgOutput As System.Windows.Forms.DataGrid Friend WithEvents lblOutput As System.Windows.Forms.Label Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem Friend WithEvents mnuOpenCompare As System.Windows.Forms.MenuItem Friend WithEvents mnuOpenStandard As System.Windows.Forms.MenuItem Friend WithEvents mnuExit As System.Windows.Forms.MenuItem Friend WithEvents MenuItem5 As System.Windows.Forms.MenuItem Friend WithEvents mnuCompare As System.Windows.Forms.MenuItem Friend WithEvents MenuItem7 As System.Windows.Forms.MenuItem Friend WithEvents mnuInstructions As System.Windows.Forms.MenuItem Friend WithEvents mnuVersionHistory As System.Windows.Forms.MenuItem Friend WithEvents mnuAbout As System.Windows.Forms.MenuItem Friend WithEvents btnSelectStandard As System.Windows.Forms.Button Friend WithEvents btnSelectCompare As System.Windows.Forms.Button Private Sub InitializeComponent() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1)) Me.Label1 = New System.Windows.Forms.Label Me.lblStdFileName = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.lblCompareFileName = New System.Windows.Forms.Label Me.btnCompare = New System.Windows.Forms.Button Me.Label5 = New System.Windows.Forms.Label Me.Label6 = New System.Windows.Forms.Label Me.Label2 = New System.Windows.Forms.Label Me.lblStdRecs = New System.Windows.Forms.Label Me.Label7 = New System.Windows.Forms.Label Me.lblCompareRecs = New System.Windows.Forms.Label Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog Me.grpVertical = New System.Windows.Forms.GroupBox Me.grpHorizontal = New System.Windows.Forms.GroupBox Me.dtgOutput = New System.Windows.Forms.DataGrid Me.lblOutput = New System.Windows.Forms.Label Me.MainMenu1 = New System.Windows.Forms.MainMenu Me.MenuItem1 = New System.Windows.Forms.MenuItem Me.mnuOpenCompare = New System.Windows.Forms.MenuItem Me.mnuOpenStandard = New System.Windows.Forms.MenuItem Me.mnuExit = New System.Windows.Forms.MenuItem Me.MenuItem5 = New System.Windows.Forms.MenuItem Me.mnuCompare = New System.Windows.Forms.MenuItem Me.MenuItem7 = New System.Windows.Forms.MenuItem Me.mnuInstructions = New System.Windows.Forms.MenuItem Me.mnuVersionHistory = New System.Windows.Forms.MenuItem Me.mnuAbout = New System.Windows.Forms.MenuItem Me.btnSelectStandard = New System.Windows.Forms.Button Me.btnSelectCompare = New System.Windows.Forms.Button Me.grpVertical.SuspendLayout() Me.grpHorizontal.SuspendLayout() CType(Me.dtgOutput, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'Label1 ' Me.Label1.Location = New System.Drawing.Point(0, 56) Me.Label1.Name = "Label1" Me.Label1.Size = New System.Drawing.Size(120, 16) Me.Label1.TabIndex = 0 Me.Label1.Text = "Standard File Name:" ' 'lblStdFileName ' Me.lblStdFileName.AllowDrop = True Me.lblStdFileName.BackColor = System.Drawing.Color.White Me.lblStdFileName.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.lblStdFileName.Location = New System.Drawing.Point(0, 72) Me.lblStdFileName.Name = "lblStdFileName" Me.lblStdFileName.Size = New System.Drawing.Size(544, 32) Me.lblStdFileName.TabIndex = 1 ' 'Label3 ' Me.Label3.Location = New System.Drawing.Point(0, 120) Me.Label3.Name = "Label3" Me.Label3.Size = New System.Drawing.Size(112, 16) Me.Label3.TabIndex = 2 Me.Label3.Text = "Compare File Name:" ' 'lblCompareFileName ' Me.lblCompareFileName.AllowDrop = True Me.lblCompareFileName.BackColor = System.Drawing.Color.White Me.lblCompareFileName.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.lblCompareFileName.Location = New System.Drawing.Point(0, 136) Me.lblCompareFileName.Name = "lblCompareFileName" Me.lblCompareFileName.Size = New System.Drawing.Size(544, 32) Me.lblCompareFileName.TabIndex = 3 ' 'btnCompare ' Me.btnCompare.Location = New System.Drawing.Point(24, 32) Me.btnCompare.Name = "btnCompare" Me.btnCompare.Size = New System.Drawing.Size(136, 136) Me.btnCompare.TabIndex = 6 Me.btnCompare.Text = "Compare Files" ' 'Label5 ' Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.Location = New System.Drawing.Point(16, 8) Me.Label5.Name = "Label5" Me.Label5.Size = New System.Drawing.Size(512, 32) Me.Label5.TabIndex = 11 Me.Label5.Text = "This utility will compare two files with FOOD-TRAK version info - see help for mo" & _ "re details" ' 'Label6 ' Me.Label6.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label6.Location = New System.Drawing.Point(0, 176) Me.Label6.Name = "Label6" Me.Label6.Size = New System.Drawing.Size(136, 16) Me.Label6.TabIndex = 12 Me.Label6.Text = "Comparison Results:" ' 'Label2 ' Me.Label2.Location = New System.Drawing.Point(32, 240) Me.Label2.Name = "Label2" Me.Label2.Size = New System.Drawing.Size(136, 23) Me.Label2.TabIndex = 13 Me.Label2.Text = "Standard Records Read:" ' 'lblStdRecs ' Me.lblStdRecs.BackColor = System.Drawing.Color.White Me.lblStdRecs.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.lblStdRecs.Location = New System.Drawing.Point(32, 264) Me.lblStdRecs.Name = "lblStdRecs" Me.lblStdRecs.Size = New System.Drawing.Size(120, 23) Me.lblStdRecs.TabIndex = 14 ' 'Label7 ' Me.Label7.Location = New System.Drawing.Point(32, 320) Me.Label7.Name = "Label7" Me.Label7.Size = New System.Drawing.Size(136, 23) Me.Label7.TabIndex = 15 Me.Label7.Text = "Compare Records Read:" ' 'lblCompareRecs ' Me.lblCompareRecs.BackColor = System.Drawing.Color.White Me.lblCompareRecs.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.lblCompareRecs.Location = New System.Drawing.Point(32, 344) Me.lblCompareRecs.Name = "lblCompareRecs" Me.lblCompareRecs.Size = New System.Drawing.Size(120, 23) Me.lblCompareRecs.TabIndex = 16 ' 'grpVertical ' Me.grpVertical.Controls.Add(Me.btnSelectStandard) Me.grpVertical.Controls.Add(Me.Label3) Me.grpVertical.Controls.Add(Me.lblCompareFileName) Me.grpVertical.Controls.Add(Me.lblStdFileName) Me.grpVertical.Controls.Add(Me.Label6) Me.grpVertical.Controls.Add(Me.Label5) Me.grpVertical.Controls.Add(Me.Label1) Me.grpVertical.Controls.Add(Me.btnSelectCompare) Me.grpVertical.Location = New System.Drawing.Point(0, 0) Me.grpVertical.Name = "grpVertical" Me.grpVertical.Size = New System.Drawing.Size(584, 200) Me.grpVertical.TabIndex = 18 Me.grpVertical.TabStop = False ' 'grpHorizontal ' Me.grpHorizontal.Controls.Add(Me.lblCompareRecs) Me.grpHorizontal.Controls.Add(Me.btnCompare) Me.grpHorizontal.Controls.Add(Me.Label7) Me.grpHorizontal.Controls.Add(Me.lblStdRecs) Me.grpHorizontal.Controls.Add(Me.Label2) Me.grpHorizontal.Location = New System.Drawing.Point(584, 0) Me.grpHorizontal.Name = "grpHorizontal" Me.grpHorizontal.Size = New System.Drawing.Size(184, 400) Me.grpHorizontal.TabIndex = 19 Me.grpHorizontal.TabStop = False ' 'dtgOutput ' Me.dtgOutput.AlternatingBackColor = System.Drawing.Color.Tomato Me.dtgOutput.BackColor = System.Drawing.SystemColors.Menu Me.dtgOutput.BackgroundColor = System.Drawing.Color.LightGray Me.dtgOutput.CaptionVisible = False Me.dtgOutput.DataMember = "" Me.dtgOutput.Font = New System.Drawing.Font("Courier New", 9.75!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.dtgOutput.HeaderForeColor = System.Drawing.SystemColors.ControlText Me.dtgOutput.Location = New System.Drawing.Point(0, 200) Me.dtgOutput.Name = "dtgOutput" Me.dtgOutput.ParentRowsBackColor = System.Drawing.SystemColors.ActiveCaptionText Me.dtgOutput.ReadOnly = True Me.dtgOutput.Size = New System.Drawing.Size(584, 256) Me.dtgOutput.TabIndex = 20 ' 'lblOutput ' Me.lblOutput.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblOutput.Location = New System.Drawing.Point(8, 232) Me.lblOutput.Name = "lblOutput" Me.lblOutput.Size = New System.Drawing.Size(560, 32) Me.lblOutput.TabIndex = 21 ' 'MainMenu1 ' Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1, Me.MenuItem5, Me.MenuItem7}) ' 'MenuItem1 ' Me.MenuItem1.Index = 0 Me.MenuItem1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuOpenCompare, Me.mnuOpenStandard, Me.mnuExit}) Me.MenuItem1.Text = "&File" ' 'mnuOpenCompare ' Me.mnuOpenCompare.Index = 0 Me.mnuOpenCompare.Text = "Open &Compare File" ' 'mnuOpenStandard ' Me.mnuOpenStandard.Index = 1 Me.mnuOpenStandard.Text = "Open &Standard File" ' 'mnuExit ' Me.mnuExit.Index = 2 Me.mnuExit.Text = "&Exit" ' 'MenuItem5 ' Me.MenuItem5.Index = 1 Me.MenuItem5.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuCompare}) Me.MenuItem5.Text = "&Compare" ' 'mnuCompare ' Me.mnuCompare.Index = 0 Me.mnuCompare.Text = "&Run Comparison" ' 'MenuItem7 ' Me.MenuItem7.Index = 2 Me.MenuItem7.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuInstructions, Me.mnuVersionHistory, Me.mnuAbout}) Me.MenuItem7.Text = "&Help" ' 'mnuInstructions ' Me.mnuInstructions.Index = 0 Me.mnuInstructions.Text = "&Instructions to Use" ' 'mnuVersionHistory ' Me.mnuVersionHistory.Index = 1 Me.mnuVersionHistory.Text = "&Version History" ' 'mnuAbout ' Me.mnuAbout.Index = 2 Me.mnuAbout.Text = "&About" ' 'btnSelectStandard ' Me.btnSelectStandard.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnSelectStandard.Location = New System.Drawing.Point(544, 72) Me.btnSelectStandard.Name = "btnSelectStandard" Me.btnSelectStandard.Size = New System.Drawing.Size(32, 32) Me.btnSelectStandard.TabIndex = 13 Me.btnSelectStandard.Text = "..." ' 'btnSelectCompare ' Me.btnSelectCompare.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.btnSelectCompare.Location = New System.Drawing.Point(544, 136) Me.btnSelectCompare.Name = "btnSelectCompare" Me.btnSelectCompare.Size = New System.Drawing.Size(32, 32) Me.btnSelectCompare.TabIndex = 13 Me.btnSelectCompare.Text = "..." ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(800, 453) Me.Controls.Add(Me.lblOutput) Me.Controls.Add(Me.dtgOutput) Me.Controls.Add(Me.grpHorizontal) Me.Controls.Add(Me.grpVertical) Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon) Me.Menu = Me.MainMenu1 Me.MinimumSize = New System.Drawing.Size(800, 480) Me.Name = "Form1" Me.Text = "FOOD-TRAK File Version Comparison" Me.grpVertical.ResumeLayout(False) Me.grpHorizontal.ResumeLayout(False) CType(Me.dtgOutput, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private Sub btnCompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompare.Click RunComparison() End Sub Private Sub RunComparison() 'This is the main routine in the program and actually does the comparison of the files. 'Program logic will flow as follows: ' 'If standard and compare files opened okay ' Clear out record counters ' Read first records in both files ' Loop until EOF on either file ' If filenames equal ' perform version compare, report if different ' read new records from both files ' increment both record read counters ' Elseif StandardFTfile > CompareFTfile ' Loop until StandardFTfile = CompareFTfile or ' StandardFTfile < CompareFTfile or ' EOF on compare file ' flag StandardFTfile as missing ' read next compare record ' increment compare record counter ' End loop ' Elseif StandardFTfile < CompareFTfile ' Loop until StandardFTfile = CompareFTfile or ' StandardFTfile > CompareFTfile or ' EOF on standard file ' flag CompareFTfile as missing ' read next standard record ' increment standard record counter ' End loop ' EndIf ' EndLoop ' If EOF on Standard ' read compare until EOF, flag each record as missing in standard ' Elseif EOF on Compare ' read Standard until EOF, flag each record as missing in compare Dim StandardFTRec, CompareFTRec As String Dim StandardFTFile, StandardFTVersion As String Dim CompareFTFile, CompareFTVersion As String Dim StandardRecsRead, CompareRecsRead, RecsDifferent As Integer Dim StandardEOF, CompareEOF As Boolean 'Here are the report output arrays and pointer Dim ReportFileName(900) As String Dim ReportStandard(900) As String Dim ReportCompare(900) As String Dim intReportArrayPointer As Integer If Not StandardFileNameOK Or Not CompareFileNameOK Then MsgBox("Please verify that both the Standard and Compare files have been" & vbNewLine & _ "specified before requesting a comparison" & vbNewLine & vbNewLine & _ "On the form, both Standard and Compare filenames will be displayed" & vbNewLine & _ "if the file names have been accepted.") Exit Sub End If 'At this point we are going to open both files - this will allow us to start at the beginning of 'the file if the file was used in a previous compare Try Comparefile = New StreamReader(strCompareFileName) Catch ex As Exception MsgBox("Error opening compare file, error from Windows is:" & vbNewLine & ex.Message) Exit Sub End Try Try StandardFile = New StreamReader(strStandardFileName) Catch ex As Exception MsgBox("Error opening standard file, error from Windows is:" & vbNewLine & ex.Message) Exit Sub End Try If StandardFile.Peek = -1 Or Comparefile.Peek = -1 Then MsgBox("One or both of the files is empty!") Exit Sub End If 'If either file is empty we cannot do a compare 'We have two files open and they have data, let's read the first recs StandardFTRec = StandardFile.ReadLine CompareFTRec = Comparefile.ReadLine 'We still have one check to perform, does the first line have data? If (LTrim(StandardFTRec) = "") Or _ (LTrim(CompareFTRec) = "") Then MsgBox("One or both files are not the correct format" & vbNewLine & _ "The file should contain a list of file names " & vbNewLine & _ "and version numbers. Please consult the built-in" & vbNewLine & _ "help for more information.") Exit Sub End If ' btnCompare.Enabled = False ' btnOpenStd.Enabled = False ' btnOpenCompare.Enabled = False StandardRecsRead += 1 CompareRecsRead += 1 SplitString(StandardFTRec, StandardFTFile, StandardFTVersion) SplitString(CompareFTRec, CompareFTFile, CompareFTVersion) Do Until (StandardEOF Or CompareEOF) If (StandardFTFile = CompareFTFile) Then If (StandardFTVersion <> CompareFTVersion) Then 'Here is an output instance ReportFileName(intReportArrayPointer) = StandardFTFile ReportStandard(intReportArrayPointer) = StandardFTVersion ReportCompare(intReportArrayPointer) = CompareFTVersion intReportArrayPointer += 1 RecsDifferent += 1 End If ReadNextStandardRec(StandardFTRec, StandardEOF, StandardRecsRead) SplitString(StandardFTRec, StandardFTFile, StandardFTVersion) ReadNextCompareRec(CompareFTRec, CompareEOF, CompareRecsRead) SplitString(CompareFTRec, CompareFTFile, CompareFTVersion) ElseIf (StandardFTFile < CompareFTFile) Then Do Until ((StandardFTFile = CompareFTFile) Or _ (StandardFTFile > CompareFTFile) Or _ (StandardEOF)) 'Here is an output instance ReportFileName(intReportArrayPointer) = StandardFTFile ReportStandard(intReportArrayPointer) = StandardFTVersion ReportCompare(intReportArrayPointer) = "missing" intReportArrayPointer += 1 RecsDifferent += 1 ReadNextStandardRec(StandardFTRec, StandardEOF, StandardRecsRead) SplitString(StandardFTRec, StandardFTFile, StandardFTVersion) Loop ElseIf (StandardFTFile > CompareFTFile) Then Do Until ((StandardFTFile = CompareFTFile) Or _ (StandardFTFile < CompareFTFile) Or _ (CompareEOF)) 'Here is an output instance ReportFileName(intReportArrayPointer) = CompareFTFile ReportStandard(intReportArrayPointer) = "missing" ReportCompare(intReportArrayPointer) = CompareFTVersion intReportArrayPointer += 1 RecsDifferent += 1 ReadNextCompareRec(CompareFTRec, CompareEOF, CompareRecsRead) SplitString(CompareFTRec, CompareFTFile, CompareFTVersion) Loop End If Loop If StandardEOF And CompareEOF Then lblStdRecs.Text = CStr(StandardRecsRead) lblCompareRecs.Text = CStr(CompareRecsRead) If RecsDifferent = 0 Then lblOutput.Text = "These two files appear identical, no differences could be found." lblOutput.Show() Exit Sub End If End If If StandardEOF Then Do Until CompareEOF 'Here is an output instance ReportFileName(intReportArrayPointer) = CompareFTFile ReportStandard(intReportArrayPointer) = "missing" ReportCompare(intReportArrayPointer) = CompareFTVersion intReportArrayPointer += 1 RecsDifferent += 1 ReadNextCompareRec(CompareFTRec, CompareEOF, CompareRecsRead) SplitString(CompareFTRec, CompareFTFile, CompareFTVersion) Loop ElseIf CompareEOF Then Do Until StandardEOF 'Here is an output instance ReportFileName(intReportArrayPointer) = StandardFTFile ReportStandard(intReportArrayPointer) = StandardFTVersion ReportCompare(intReportArrayPointer) = "missing" intReportArrayPointer += 1 RecsDifferent += 1 ReadNextStandardRec(StandardFTRec, StandardEOF, StandardRecsRead) SplitString(StandardFTRec, StandardFTFile, StandardFTVersion) Loop End If lblStdRecs.Text = CStr(StandardRecsRead) lblCompareRecs.Text = CStr(CompareRecsRead) WriteOutputReport(ReportFileName, ReportStandard, ReportCompare, _ intReportArrayPointer) 'We are going to close both files here because even if we want to do the 'compare again on the same files they need to be re-opened to reset to the start StandardFile.Close() Comparefile.Close() End Sub Private Sub btnOpenStd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) SpecifyStandardFile() End Sub Private Sub btnOpenCompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) SpecifyCompareFile() End Sub Private Sub SpecifyStandardFile() OpenFileDialog1.Filter = "Text files (*.txt)|*.txt" If OpenFileDialog1.ShowDialog() = DialogResult.OK Then strStandardFileName = OpenFileDialog1.FileName lblStdFileName.Text = "" 'StandardFile = New StreamReader(StandardFilename) lblStdFileName.Text = strStandardFileName StandardFileNameOK = True ClearForm() End If End Sub Private Sub SpecifyCompareFile() OpenFileDialog1.Filter = "Text files (*.txt)|*.txt" If OpenFileDialog1.ShowDialog() = DialogResult.OK Then strCompareFileName = OpenFileDialog1.FileName lblCompareFileName.Text = "" lblCompareFileName.Text = strCompareFileName CompareFileNameOK = True ClearForm() End If End Sub Private Sub lblStdFileName_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblStdFileName.DragDrop If e.Data.GetDataPresent(DataFormats.FileDrop) Then Dim sFiles() As String = e.Data.GetData(DataFormats.FileDrop) If IsFileTXT(sFiles(0)) Then lblStdFileName.Text = "" lblStdFileName.Text = sFiles(0) strStandardFileName = sFiles(0) StandardFileNameOK = True ClearForm() End If End If End Sub Private Sub lblCompareFileName_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblCompareFileName.DragDrop If e.Data.GetDataPresent(DataFormats.FileDrop) Then Dim sFiles() As String = e.Data.GetData(DataFormats.FileDrop) If IsFileTXT(sFiles(0)) Then ' Comparefile = New StreamReader(sFiles(0)) lblCompareFileName.Text = "" lblCompareFileName.Text = sFiles(0) strCompareFileName = sFiles(0) CompareFileNameOK = True ClearForm() End If End If End Sub Private Sub ClearForm() ' Clear all labels and text boxes on the form ' reset counters ' lblCompareRecs.Text = "" lblStdRecs.Text = "" intLargestFileNameLength = 0 intLargestVersionNumberLength = 0 dtgOutput.Hide() lblOutput.Hide() End Sub Private Sub SplitString(ByVal InputString As String, ByRef FileNameString As String, ByRef VersionString As String) 'This routine splits each input string into the filename and version number 'The filename is upshifted to allow for more consistent checking between 'the standard and compare files Dim SplitPos As Integer SplitPos = InStr(InputString, " ") If SplitPos = 0 Then 'attempting not to crash.... MsgBox("Program has located corrupted data in input file") Exit Sub End If FileNameString = UCase(Microsoft.VisualBasic.Left(InputString, SplitPos - 1)) VersionString = Mid(InputString, SplitPos + 1) If intLargestFileNameLength < FileNameString.Length() Then intLargestFileNameLength = FileNameString.Length If intLargestVersionNumberLength < VersionString.Length() Then intLargestVersionNumberLength = VersionString.Length End Sub Private Sub ReadNextStandardRec(ByRef StandardFTRec As String, ByRef StandardEOF As Boolean, ByRef StandardRecsRead As Integer) If StandardFile.Peek <> -1 Then StandardFTRec = StandardFile.ReadLine StandardRecsRead += 1 Else StandardEOF = True End If ' If we find a null record, pad with spaces to avoid crash If StandardFTRec = "" Then StandardFTRec = " " End Sub Private Sub ReadNextCompareRec(ByRef CompareFTRec As String, ByRef CompareEOF As Boolean, ByRef CompareRecsRead As Integer) If Comparefile.Peek <> -1 Then CompareFTRec = Comparefile.ReadLine CompareRecsRead += 1 Else CompareEOF = True End If ' If we find a null record, pad with spaces to avoid crash If CompareFTRec = "" Then CompareFTRec = " " End Sub Private Sub WriteOutputReport(ByVal Filenames() As String, ByVal Standard() As String, _ ByVal Compare() As String, ByVal EndOfArray As Integer) 'This routine will be responsible for formatting the report on the screen in 'an easy-to-read format. The formatting of the report in this fashion was 'devised when FOOD-TRAK program file names varied in length between 11 bytes 'and 46 bytes and yet we somehow needed to display them in a readable 'fashion. 'filename standard compare lblOutput.Hide() Dim dsOutputDataset As New DataSet("OutputDataSet") Dim dtOutputDatatable As DataTable = dsOutputDataset.Tables.Add("OutputDataTable") Dim OneRow As DataRow With dtOutputDatatable .Columns.Add("Filename", Type.GetType("System.String")) .Columns.Add("Standard", Type.GetType("System.String")) .Columns.Add("Compare", Type.GetType("System.String")) End With 'create a new row with the same structure as that in the table dtgOutput.DataSource = dsOutputDataset.Tables(0) Dim ts As New DataGridTableStyle ts.MappingName = dsOutputDataset.Tables(0).ToString dtgOutput.TableStyles.Clear() dtgOutput.TableStyles.Add(ts) ts.GridColumnStyles(0).Width = CInt(intLargestFileNameLength * 8.5) ts.GridColumnStyles(1).Width = CInt(intLargestVersionNumberLength * 8.5) ts.GridColumnStyles(2).Width = CInt(intLargestVersionNumberLength * 8.5) ts.AlternatingBackColor = Color.LightCyan Dim intArrayPointer As Integer For intArrayPointer = 0 To EndOfArray - 1 OneRow = dsOutputDataset.Tables(0).NewRow OneRow("FileName") = Filenames(intArrayPointer) OneRow("Standard") = Standard(intArrayPointer) OneRow("Compare") = Compare(intArrayPointer) dsOutputDataset.Tables(0).Rows.Add(OneRow) Next dtgOutput.Show() End Sub Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize 'When the size of the form changes, we want to maximize the size 'of the output area to display more data dtgOutput.Width = Me.ClientSize.Width - grpHorizontal.Width grpVertical.Width = dtgOutput.Width grpHorizontal.Left = Me.ClientSize.Width - grpHorizontal.Width dtgOutput.Height = Me.ClientSize.Height - grpVertical.Height End Sub Private Sub lblCompareFileName_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblCompareFileName.DragEnter e.Effect = DragDropEffects.All End Sub Private Sub lblStdFileName_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles lblStdFileName.DragEnter e.Effect = DragDropEffects.All End Sub 'Design thoughts - instead of having a clear function, the clear should happen when a new filename is 'accepted into the system if there was a previous compare ' 'However, we need to think about how to reset - this means the open file buttons will always be enabled 'even right after a compare. It means that if an open button is clicked and a new file is accepted or 'if there is a drag and drop that is accepted we need to clear our values (for our file) and then 'do a master clear of the previous results. ' 'There needs to be a validate function for the incoming drag and drop filename that will not allow a 'file if it does not have an extension and is not TXT ' 'We want to move several buttons to a menubar at the top of the form, include sections for version and 'history. The only buttons on the form should be open compare, open standard, and compare ' Function IsFileTXT(ByVal Filename As String) As Boolean 'This function will examine a filename dropped onto the form and will return true if is is a 'filename with a .TXT extension. Here are the steps for this operation: ' ' 1. Get the actual filename after the last "\" character ' 2. Verify that there is a period in the filename denoting an extension - if not, display message and return false ' 3. Verify that the extension is TXT or txt - if not, display message and return false ' 4. If you have gotten to the end, return true Dim intCharacterCounter, intTotalLength As Integer 'Get the total length of the string intTotalLength = Len(Filename) 'Find the last "\" character in the string intCharacterCounter = InStrRev(Filename, "\") If intCharacterCounter = 0 Then MsgBox("The filename appears to be totally invalid, never found a '\' character in the string!") Return False End If 'change the string so it only has the filename after the last '\' Filename = Microsoft.VisualBasic.Right(Filename, intTotalLength - intCharacterCounter) 'find the last period in the filename intCharacterCounter = InStrRev(Filename, ".") If intCharacterCounter = 0 Then MsgBox("The filename does not appear to have an extension, we need a TXT extension to process it.") Return False End If 'Get the length of the string now intTotalLength = Len(Filename) 'change the string so we only have the extension after the '.' Filename = Microsoft.VisualBasic.Right(Filename, intTotalLength - intCharacterCounter) 'take out leading and trailing spaces Filename = Trim(Filename) 'verify that it is a three-character extension If Not Len(Filename) = 3 Then MsgBox("The filename does not appear to have a three-character extension, we need a TXT extension to process it.") Return False End If 'check extension to see if it is txt If UCase(Filename) = "TXT" Then Return True Else MsgBox("We can only process the file if it has an extension of TXT.") Return False End If End Function Private Sub btnSelectStandard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectStandard.Click SpecifyStandardFile() End Sub Private Sub btnSelectCompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelectCompare.Click SpecifyCompareFile() End Sub Private Sub mnuOpenCompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpenCompare.Click SpecifyCompareFile() End Sub Private Sub mnuOpenStandard_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuOpenStandard.Click SpecifyStandardFile() End Sub Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click Me.Close() End Sub Private Sub mnuCompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCompare.Click RunComparison() End Sub Private Sub mnuInstructions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuInstructions.Click MsgBox("This utility is designed to compare two files containing FOOD-TRAK" & vbNewLine & _ "version information and will display any discrepancies between the files." & vbNewLine & _ vbNewLine & _ "Although the program does verify that both files are open and" & vbNewLine & _ "both contain data, there is no other data checking performed." & vbNewLine & _ "The thought was that any attempt to determine if the file truly" & vbNewLine & _ "contains FOOD-TRAK file information might limit its use in a" & vbNewLine & _ "future release of FOOD-TRAK when the file names might be different" & vbNewLine & _ vbNewLine & _ "This is an extract from a version file showing the correct format:" & vbNewLine & _ vbNewLine & _ "_frmupdt.exe 1.0.14" & vbNewLine & _ "AcctEdit.dll 2.0.22" & vbNewLine & _ "Acctedit.exe 1.0.1" & vbNewLine & _ "Acctwiz.exe 1.0.30" & vbNewLine & _ vbNewLine & _ "The standard file is assumed to be the fileversion output from a" & vbNewLine & _ "known good version of FOOD-TRAK, the version running at SCI." & vbNewLine & _ "The compare file will contain version data from the customer site" & vbNewLine & _ vbNewLine & _ "This program will flag any instances where:" & vbNewLine & _ "1. The file is at SCI and not at the customer site" & vbNewLine & _ "2. The file is at the customer site but not SCI" & vbNewLine & _ "3. The file is at both sites but the version number is different") End Sub Private Sub mnuVersionHistory_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuVersionHistory.Click MsgBox("Version History:" & vbNewLine & _ "1.0.0 10-25-2003 Initial Creation" & vbNewLine & _ "1.0.1 01-02-2004 Modified to check first line of each file - if the first" & vbNewLine & _ " line contains blanks or a null, flag as invalid format and" & vbNewLine & _ " display error" & vbNewLine & _ "1.0.2 12-05-2004 Modified to display output in data grid to allow for " & vbNewLine & _ " varying file names" & vbNewLine & _ "1.0.3 10-15-2005 Modified to allow drag and drop of files for standard and compare" & vbNewLine & _ " Adding file menu on top of form, removing some buttons from form" & vbNewLine & _ " Adding version history into help menu") End Sub Private Sub mnuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAbout.Click MsgBox("FOOD-TRAK file version compare" & vbNewLine & _ "Created by Phil Persson for SCI" & vbNewLine & _ " Version 1.0.3" & vbNewLine & _ " 10-15-2005") End Sub End Class