cteakle
asked on
How to generate the MD5 hash of a file using VBA
I am working on a file management application using microsoft access. Users will be selecting a file to "file" into the relevant directory according to given parameters. I want to generate the MD5 hash of files that have already been "filed". When the user goes to file a new file, the md5 hash value of the new file will be calculated - and checked against the existing "filed" files to check for duplicates. Does anyone know of a source of VBA code that I can use to generate these values.
I havent posted many questions to this forum - have nearly always been able to find exactly what I want by searching other questions. I have allocated maximum points because I havent been able to find a solution elsewhere.
I havent posted many questions to this forum - have nearly always been able to find exactly what I want by searching other questions. I have allocated maximum points because I havent been able to find a solution elsewhere.
https://www.experts-exchange.com/questions/23862572/How-do-I-generate-an-MD5-hash-in-MS-Access-2003.html
ASKER
Hi Peter57r
I had a look at that post and tried to import the code into my vba without success. However, one difference is that I want to start with a file - not some string and generate the value for the file
Thanks
I had a look at that post and tried to import the code into my vba without success. However, one difference is that I want to start with a file - not some string and generate the value for the file
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Peter
I will have a try using this code tonight (australian time)
I will have a try using this code tonight (australian time)
ASKER
Hi again Peter - or whomever may be reading these posts. I remember why I couldnt get this to work before when I tried it on just a string. I have put Xs around the line of code that causes a problem. I get a "cannot divide by zero" message, no matter what string I enter. The problem for me is I have no idea at all what the code is doing, so dont know where to look to try and solve the problem. The other bit seemed to work though on converting a file to a string in order to use the code.
' We do not care about the top most bit or the final bit, the top most bit
' will be taken into account in the next stage, the final bit (whether it
' is an odd number or not) is being shifted into, so we do not give a jot
' about it
XXXX RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)XXXX
' If the top most bit (&H80000000) was set we need to do things differently
' as in a normal VB signed long integer the top most bit is used to indicate
' the sign of the number, when it is set it is a negative number, so just
' deviding by a factor of 2 as above would not work.
' NOTE: (lValue And &H80000000) is equivalent to (lValue < 0), you could
' get a very marginal speed improvement by changing the test to (lValue < 0)
' We do not care about the top most bit or the final bit, the top most bit
' will be taken into account in the next stage, the final bit (whether it
' is an odd number or not) is being shifted into, so we do not give a jot
' about it
XXXX RShift = (lValue And &H7FFFFFFE) \ m_l2Power(iShiftBits)XXXX
' If the top most bit (&H80000000) was set we need to do things differently
' as in a normal VB signed long integer the top most bit is used to indicate
' the sign of the number, when it is set it is a negative number, so just
' deviding by a factor of 2 as above would not work.
' NOTE: (lValue And &H80000000) is equivalent to (lValue < 0), you could
' get a very marginal speed improvement by changing the test to (lValue < 0)
ASKER
Sorry - my ignorance. I had to do a bit more research on classes. I hadnt inserted the module as a class module. All seems to be working properly now. Thanks very much for your help Peter