Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6.CopyArray Question

Posted on 2006-11-14
6
Medium Priority
?
1,122 Views
Last Modified: 2008-01-09
I have tried to converet Fresle's CGenericRegistration and CMD5 classes from VB6 to VB.Net 2005. (www.frez.co.uk/registration.zip)  The wizard converts the TestRegistration program, which includes the classes and two others, and runs fine when AscB is replaced with Asc, although the results are not the same. The wizard inserts the following code in the ConvertToWordArray function:

ConvertToWordArray = vb6.copyarray (lWordArray)

This works great when run in the IDE but when the classes are put into a class library this line gives a "VB6 not defined" type error.
The following import statement is in both the TestRegistration program and the Class Library project:

Imports VB = Microsoft.VisualBasic

I have been unable to find where the VB6.CopyArray method is located or what method is available to duplicate the functionality.
Any help would be greatly appreciated. Both VB6 and VB.Net 2005 versions follow.

*******************************************************************
VB6 code:

Private Function ConvertToWordArray(sMessage As String) As Long()
    Dim lMessageLength  As Long
    Dim lNumberOfWords  As Long
    Dim lWordArray()    As Long
    Dim lBytePosition   As Long
    Dim lByteCount      As Long
    Dim lWordCount      As Long
    Dim lChar           As Long
   
    Const MODULUS_BITS      As Long = 512
    Const CONGRUENT_BITS    As Long = 448
   
    lMessageLength = Len(sMessage)
   
    ' Get padded number of words. Message needs to be congruent to 448 bits,
    ' modulo 512 bits. If it is exactly congruent to 448 bits, modulo 512 bits
    ' it must still have another 512 bits added. 512 bits = 64 bytes
    ' (or 16 * 4 byte words), 448 bits = 56 bytes. This means lMessageSize must
    ' be a multiple of 16 (i.e. 16 * 4 (bytes) * 8 (bits))
    lNumberOfWords = (((lMessageLength + _
        ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ _
        (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * _
        (MODULUS_BITS \ BITS_TO_A_WORD)
    ReDim lWordArray(lNumberOfWords - 1)
   
    ' Combine each block of 4 bytes (ascii code of character) into one long
    ' value and store in the message. The high-order (most significant) bit of
    ' each byte is listed first. However, the low-order (least significant) byte
    ' is given first in each word.
    lBytePosition = 0
    lByteCount = 0
    Do Until lByteCount >= lMessageLength
        ' Each word is 4 bytes
        lWordCount = lByteCount \ BYTES_TO_A_WORD
               
        ' The bytes are put in the word from the right most edge
        lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
        lChar = AscB(Mid(sMessage, lByteCount + 1, 1))
        lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(lChar, lBytePosition)
        lByteCount = lByteCount + 1
    Loop

    ' Terminate according to MD5 rules with a 1 bit, zeros and the length in
    ' bits stored in the last two words
    lWordCount = lByteCount \ BYTES_TO_A_WORD
    lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE

    ' Add a terminating 1 bit, all the rest of the bits to the end of the
    ' word array will default to zero
    lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80, lBytePosition)

    ' We put the length of the message in bits into the last two words, to get
    ' the length in bits we need to multiply by 8 (or left shift 3). This left
    ' shifted value is put in the first word. Any bits shifted off the left edge
    ' need to be put in the second word, we can work out which bits by shifting
    ' right the length by 29 bits.
    lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
    lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)
   
    ConvertToWordArray = lWordArray
End Function

******************************************************
VB.Net 2005 Code:

      Private Function ConvertToWordArray(ByRef sMessage As String) As Integer()
            Dim lMessageLength As Integer
            Dim lNumberOfWords As Integer
            Dim lWordArray() As Integer
            Dim lBytePosition As Integer
            Dim lByteCount As Integer
            Dim lWordCount As Integer
            Dim lChar As Integer
            
            Const MODULUS_BITS As Integer = 512
            Const CONGRUENT_BITS As Integer = 448
            
            lMessageLength = Len(sMessage)
            
            ' Get padded number of words. Message needs to be congruent to 448 bits,
            ' modulo 512 bits. If it is exactly congruent to 448 bits, modulo 512 bits
            ' it must still have another 512 bits added. 512 bits = 64 bytes
            ' (or 16 * 4 byte words), 448 bits = 56 bytes. This means lMessageSize must
            ' be a multiple of 16 (i.e. 16 * 4 (bytes) * 8 (bits))
            lNumberOfWords = (((lMessageLength + ((MODULUS_BITS - CONGRUENT_BITS) \ BITS_TO_A_BYTE)) \ (MODULUS_BITS \ BITS_TO_A_BYTE)) + 1) * (MODULUS_BITS \ BITS_TO_A_WORD)
            ReDim lWordArray(lNumberOfWords - 1)
            
            ' Combine each block of 4 bytes (ascii code of character) into one long
            ' value and store in the message. The high-order (most significant) bit of
            ' each byte is listed first. However, the low-order (least significant) byte
            ' is given first in each word.
            lBytePosition = 0
            lByteCount = 0
            Do Until lByteCount >= lMessageLength
                  ' Each word is 4 bytes
                  lWordCount = lByteCount \ BYTES_TO_A_WORD
                  
                  ' The bytes are put in the word from the right most edge
                  lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
            ' lChar = AscB(Mid(sMessage, lByteCount + 1, 1)) AscB no longer supported.
            lChar = Asc(Mid(sMessage, lByteCount + 1, 1))

            lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(lChar, lBytePosition)
                  lByteCount = lByteCount + 1
            Loop
            
            ' Terminate according to MD5 rules with a 1 bit, zeros and the length in
            ' bits stored in the last two words
            lWordCount = lByteCount \ BYTES_TO_A_WORD
            lBytePosition = (lByteCount Mod BYTES_TO_A_WORD) * BITS_TO_A_BYTE
            
            ' Add a terminating 1 bit, all the rest of the bits to the end of the
            ' word array will default to zero
            lWordArray(lWordCount) = lWordArray(lWordCount) Or LShift(&H80s, lBytePosition)
            
            ' We put the length of the message in bits into the last two words, to get
            ' the length in bits we need to multiply by 8 (or left shift 3). This left
            ' shifted value is put in the first word. Any bits shifted off the left edge
            ' need to be put in the second word, we can work out which bits by shifting
            ' right the length by 29 bits.
            lWordArray(lNumberOfWords - 2) = LShift(lMessageLength, 3)
            lWordArray(lNumberOfWords - 1) = RShift(lMessageLength, 29)
            
        ConvertToWordArray = VB6.CopyArray(lWordArray)

      End Function
0
Comment
Question by:rkulp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 17944705
Hi rkulp,

You will probably need to use the following import instead (this gives you the VB6 stuff)

Imports Microsoft.VisualBasic.Compatibility

note that you will need to add a project reference to the "Microsoft Visual Basic .NET Compatibility Runtime".

Cheers!
0
 
LVL 1

Author Comment

by:rkulp
ID: 17946146
Hilwaaa,

Thanks for the suggestion. Unfortunately, that did not resolve the problem, but I am sure you are on the right track. Going down to the VisualBasic.Compatibility.VB6 namespace did not help as CopyArray is not in the namespace.

I did some more testing this morning and discovered what I should have discovered at first:

ConvertToWordArray = lWordArray

and

ConvertToWordArray = VB6.CopyArray(lWordArray)

yielded exactly the same ConvertToWordArray result.  That meant the problem was really in the calling program. I found it and all is now well.

I will close this question even though it means I may never know where VB6.CopyArray really exists.
0
 
LVL 16

Accepted Solution

by:
Hillwaaa earned 2000 total points
ID: 17950614
Hey rkulp,

CopyArray can definately be called as Microsoft.VisualBasic.Compatibility.VB6.CopyArray(System.Array).

See the msdn doco for confirmation - http://msdn2.microsoft.com/en-us/library/9a59w6f5(VS.80).aspx

Cheers,
Hillwaaa
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:rkulp
ID: 17950664
Hillwaaa:

I stand corrected. It did not appear in my VB 2005 Express IDE. My professional edition is in transit. Thanks for your help.
0
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 17950693
Ah - that's great.  Good luck with the rest of your conversion! (they can be fun :)
0
 
LVL 1

Author Comment

by:rkulp
ID: 17951000
I stand corrected again. I found it in the Express IDE. The imports statement should be:

Imports VB6 = Microsoft.VisualBasic.Compatibility.VB6

Then VB6.CopyArray will work (or you could use the fully-qualified name rather than the alias VB6)

Thanks for the encouragement. The original program is about 40,000 lines. I will try to re-write much of it in a simpler form. Great fun.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question