Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I would like to know if there is a way to compare two wave files in VB6?
If Wave1=Wave2 then
Do this
else
Do that
end ifThe above code is not VB6. It is a repesentation of what I want to do.
please help.
anything is appreciated.

What does "equal" mean? Same name? Same size? Same content? If you mean content, then I don't think you can pull it off with a simple 'if' statement. You'd probably have to open the files and compare them piece by piece. I quickly wrote the following code, but it's kinda pokey (may not be a problem if your file sizes are small... or maybe someone else will post a simpler, more efficient solution.) I'm leaving in the hard-coded file names... just replace them with whatever variables you're using. I tested it with .mp3's but it should work just as well with .wav's.
Private Sub Command1_Click()Dim intFile1 As Integer
Dim intFile2 As Integer
Dim strBuff1 As String
Dim strBuff2 As String
Dim flgEqual As Boolean
flgEqual = TrueintFile1 = FreeFile
Open "c:\piano1.mp3" For Binary As intFile1
intFile2 = FreeFile
Open "c:\piano2.mp3" For Binary As intFile2Do While Not EOF(intFile1)
Line Input #intFile1, strBuff1
Line Input #intFile2, strBuff2If strBuff1 strBuff2 Then
flgEqual = False
Exit Do
End IfLoop
If flgEqual = True Then
MsgBox "They're the same."
Else
MsgBox "They're different."
End IfClose #intFile1
Close #intFile2End Sub

Replace
If strBuff1 strBuff2 Then
with...
If strBuff1 [Not Equal] strBuff2 Then
The VB sign for Not Equal is a less-than sign immediately followed by a greater-than sign. (I tried using the HTML code for less-than, and it previewed ok, but still got stripped in the final post.)

Is it not possible to use fc.exe which is supplied with DOS and compares two files bit by bit, and call it up from VB6?

HiJinx,
I thank you very, very much.
Sorry for the misunderstanding! Yes, I meant to compare the contents of the files not the size.Your response looks great. I haven't tried it yet; however I will give it a try soon. I will make sure I let you know if it works.
I thought that I was trying something impossible.
Suppose that both wave files have the same content, but they don't have the same size.
Would the above trick still pull it off?Hukre,
I thank you for you responses as well.
I will take a look at your reference right after this post.Once again, thanks to both of you guys!

Well... from the computer's precise point of view, two files can't have the same content, but be of different sizes. I'm pretty sure I know what you're getting at though, and let's just say that the analysis required would be a wee bit more sophistocated than I offered :). My code doesn't take into account any small diferences which may exist between two files which may be otherwise pretty much the same.
What you want is possible, but it's more than I'd be capable of helping you with.

![]() |
vb: merge and save obj an...
|
VC++ DLL accessing MS ACC...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |