Hopefully Easy VB Class Question ...

This is a discussion on Hopefully Easy VB Class Question ... within the basic.visual forums in Programming Languages category; I've never utilized a VB Class module before and I am trying to incorporate an MD5 Hashing Class I downloaded into a simple test project. I've looked thru some MSDN info and can't see what I may be missing with regards to calling a public class function. I have an ultra-simple form interface to point to a file for which I want to generate the hash code. Below is the code I use to get a filepath, instantiate a class into an object, and attempt to call the public class function: - - - - - - - - - ...

Go Back   Application Development Forum > Programming Languages > basic.visual

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-04-2008, 02:28 PM
stevegdula@yahoo.com
Guest
 
Default Hopefully Easy VB Class Question ...

I've never utilized a VB Class module before and I am trying to
incorporate
an MD5 Hashing Class I downloaded into a simple test project.

I've looked thru some MSDN info and can't see what I may be missing
with
regards to calling a public class function.

I have an ultra-simple form interface to point to a file for which I
want to generate the
hash code. Below is the code I use to get a filepath, instantiate a
class into
an object, and attempt to call the public class function:
- - - - - - - - - - - - - -
Option Explicit

Public HashTool As MD5 'Class is named MD5

Private Sub Command1_Click()

Dim strFinalMD5Value As String

cdbPath.ShowOpen
lblSourcePath.Caption = cdbPath.FileName

strFinalMD5Value = HashTool.DigestFileToHexStr(lblSourcePath.Caption)
lblHashCode.Caption = strFinalMD5Value

End Sub
- - - - - - - - - - - - - -
An error is raised "Run Time Error 91", "Object Variable or With Block
not Set".
This error occurs a the line where I attempt to invoke the class
function:

"HashTool.DigestFileToHexStr()"
- - - - - - - - - - - - - -
I don't know if this error is actually occurring due to the code
contained within
the class function, and so I am including it here just in case ...

Public Function DigestFileToHexStr(FileName As String) As String
Open FileName For Binary Access Read As #1
MD5Init
Do While Not EOF(1)
Get #1, , ByteBuffer
If Loc(1) < LOF(1) Then
ByteCounter = ByteCounter + 64
MD5Transform ByteBuffer
End If
Loop
ByteCounter = ByteCounter + (LOF(1) Mod 64)
Close #1
MD5Final
DigestFileToHexStr = GetValues
End Function

Public Sub MD5Init()
ByteCounter = 0
State(1) = UnsignedToLong(1732584193#)
State(2) = UnsignedToLong(4023233417#)
State(3) = UnsignedToLong(2562383102#)
State(4) = UnsignedToLong(271733878#)
End Sub
.. . . lots of bitwise manipulations galore follow ...

Thanks for any input,

--Steve




Reply With Quote
  #2  
Old 09-04-2008, 05:30 PM
Alfie [UK]
Guest
 
Default Re: Hopefully Easy VB Class Question ...

On Thu, 4 Sep 2008 11:28:23 -0700 (PDT), stevegdula@yahoo.com wrote:

>I've never utilized a VB Class module before and I am trying to
>incorporate
>an MD5 Hashing Class I downloaded into a simple test project.
>


You don't appear to be 'creating' the class, in your Click event you
need;

Set HashTool = New MD5
--
Alfie [UK]
<http://www.delphia.co.uk/>
Girl power is fine - But who do you call when a fuse blows ?

Reply With Quote
  #3  
Old 09-04-2008, 06:45 PM
stevegdula@yahoo.com
Guest
 
Default Re: Hopefully Easy VB Class Question ...

That did the trick. Thank you.

Just to be safe I used "Set HashTool = Nothing" at the end
to assure I cleaned up the memory for this object. I'm not
sure if it is otherwise automatic after the procedure ends.

~Steve


On Sep 4, 4:30*pm, "Alfie [UK]" <al...@mail.invalid> wrote:

> On Thu, 4 Sep 2008 11:28:23 -0700 (PDT), stevegd...@yahoo.com wrote:
> >I've never utilized a VB Class module before and I am trying to
> >incorporate
> >an MD5 Hashing Class I downloaded into a simple test project.

>
> You don't appear to be 'creating' the class, in your Click event you
> need;
>
> Set HashTool = New MD5
> --
> Alfie [UK]
> <http://www.delphia.co.uk/>
> Girl power is fine - But who do you call when a fuse blows ?


Reply With Quote
  #4  
Old 09-05-2008, 04:33 AM
Jan Hyde (VB MVP)
Guest
 
Default Re: Hopefully Easy VB Class Question ...

stevegdula@yahoo.com's wild thoughts were released on Thu, 4
Sep 2008 15:45:48 -0700 (PDT) bearing the following fruit:

>That did the trick. Thank you.
>
>Just to be safe I used "Set HashTool = Nothing" at the end
>to assure I cleaned up the memory for this object. I'm not
>sure if it is otherwise automatic after the procedure ends.


It should be automatic but it still nice to do since it
clearly documents your intention.

>~Steve
>
>
>On Sep 4, 4:30*pm, "Alfie [UK]" <al...@mail.invalid> wrote:
>
>> On Thu, 4 Sep 2008 11:28:23 -0700 (PDT), stevegd...@yahoo.com wrote:
>> >I've never utilized a VB Class module before and I am trying to
>> >incorporate
>> >an MD5 Hashing Class I downloaded into a simple test project.

>>
>> You don't appear to be 'creating' the class, in your Click event you
>> need;
>>
>> Set HashTool = New MD5
>> --
>> Alfie [UK]
>> <http://www.delphia.co.uk/>
>> Girl power is fine - But who do you call when a fuse blows ?


--
Jan Hyde (VB MVP)

https://mvp.support.microsoft.com/profile/Jan.Hyde
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:26 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.