Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2008, 07:15 AM
Registered User
 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default can someone design a compare file form?

hi,

i have a code im trying to understand but its hard for me to without how the form looks like? can someone make a form how the code i provide?screenshot it that would be fine.

im not sure where would you implement this code to? i was thinkin to the button command name under Compare? but i cant get it working?
thanks

code:

    Private Function CompareFiles(ByVal filePathOne As String, ByVal filePathTwo As String) As Boolean



        Dim fileOneByte As Integer

        Dim fileTwoByte As Integer



        Dim fileOneStream As FileStream

        Dim fileTwoStream As FileStream



        ' If user has selected the same file as file one and file two....

        If (filePathOne = filePathTwo) Then

            ' Files are the same.

            Me.ResultsRichTextBox.Text = "Files are the same; file one is file two."

            Return True

        End If



        ' Open a FileStream for each file.

        fileOneStream = New FileStream(filePathOne, FileMode.Open)

        fileTwoStream = New FileStream(filePathTwo, FileMode.Open)



        ' If the files are not the same length...

        If (fileOneStream.Length <> fileTwoStream.Length) Then

            fileOneStream.Close()

            fileTwoStream.Close()

            ' File's are not equal.

            Me.ResultsRichTextBox.Text = "Files are not the same length; they are not equal."

            Return False

        End If



        Dim areFilesEqual As Boolean = True



        ' Loop through bytes in the files until

        ' a byte in file one <> a byte in file two

        ' OR

        ' end of the file one is reached.

        Do

            ' Read one byte from each file.

            fileOneByte = fileOneStream.ReadByte()

            fileTwoByte = fileTwoStream.ReadByte()

            If fileOneByte <> fileTwoByte Then

                ' Files are not equal; byte in file one <> byte in file two.

                Me.ResultsRichTextBox.Text = "Files are not equal; contents are different."

                areFilesEqual = False

                Exit Do

            End If

        Loop While (fileOneByte <> -1)



        ' Close the FileStreams.

        fileOneStream.Close()

        fileTwoStream.Close()



        Return areFilesEqual



     End Function

 
Old May 1st, 2008, 07:34 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

In the most basic form, you need a form with 2 text boxes and a submit button.

Obviously you would have to type 2 file paths into the textboxes, which isn't ideal, but it would work.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old May 1st, 2008, 07:39 AM
Registered User
 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

what if i want to include 2 more buttons command where i can press on one of them and prompts me to browse for the files instead of typing it??


if it was typing it, does it mean i can open any files in my pc as long it exist??

 
Old May 1st, 2008, 07:54 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Yes. You could use a file browser to get two files. Here is a link that demonstrates how to do this:
http://www.tech-funda.com/?p=25



================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old May 1st, 2008, 08:38 AM
Registered User
 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i have tried with the button you told me but its display at the bottom of the screen i cant put it anywhere i want??

it does not display it when i run it??

im using vb2005

 
Old May 2nd, 2008, 08:09 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

ludasky,

The file browser is a form component. It does not have any GUI itself. You need to create a textbox and a button. The button click will call a method on the file browser component that opens the browse dialog. I believe the return value of that method is a string containing the path to the selected file. Check the documentation on that component for specifics.

-Peter
peterlanoie.blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare Form Data against varchar DB record. iloveoatmeal Classic ASP Databases 16 July 2nd, 2007 01:40 PM
Please Help! Can't Design Form edove Infopath 0 May 9th, 2007 07:56 AM
compare form field to database before submit chelle60 Javascript How-To 3 January 2nd, 2007 05:42 AM
Compare "before and after" values on a form? wayne62682 Classic ASP Basics 3 May 17th, 2006 03:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.