Results 1 to 11 of 11

Thread: code conversion help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    97

    code conversion help

    hi guys i need help again. i am getting an error when i am declaring an array
    but work in vb6
    CRC_Table As Variant
    CRC_Table = Array( _
    &H0, &H1189, &H2312, &H329B, &H4624, &H57AD, &H6536, &H74BF, &H8C48, &H9DC1, &HAF5A, &HBED3, &HCA6C, &HDBE5, &HE97E, &HF8F7, &H1081, &H108, &H3393, &H221A, &H56A5, &H472C, &H75B7, &H643E, &H9CC9, &H8D40, &HBFDB, &HAE52, &HDAED, &HCB64, &HF9FF, &HE876, _
    &H2102, &H308B, &H210, &H1399, &H6726, &H76AF, &H4434, &H55BD, &HAD4A, &HBCC3, &H8E58, &H9FD1, &HEB6E, &HFAE7, &HC87C, &HD9F5, &H3183, &H200A, &H1291, &H318, &H77A7, &H662E, &H54B5, &H453C, &HBDCB, &HAC42, &H9ED9, &H8F50, &HFBEF, &HEA66, &HD8FD, &HC974, _
    &H4204, &H538D, &H6116, &H709F, &H420, &H15A9, &H2732, &H36BB, &HCE4C, &HDFC5, &HED5E, &HFCD7, &H8868, &H99E1, &HAB7A, &HBAF3, &H5285, &H430C, &H7197, &H601E, &H14A1, &H528, &H37B3, &H263A, &HDECD, &HCF44, &HFDDF, &HEC56, &H98E9, &H8960, &HBBFB, &HAA72, _
    &H6306, &H728F, &H4014, &H519D, &H2522, &H34AB, &H630, &H17B9, &HEF4E, &HFEC7, &HCC5C, &HDDD5, &HA96A, &HB8E3, &H8A78, &H9BF1, &H7387, &H620E, &H5095, &H411C, &H35A3, &H242A, &H16B1, &H738, &HFFCF, &HEE46, &HDCDD, &HCD54, &HB9EB, &HA862, &H9AF9, &H8B70, _
    &H8408, &H9581, &HA71A, &HB693, &HC22C, &HD3A5, &HE13E, &HF0B7, &H840, &H19C9, &H2B52, &H3ADB, &H4E64, &H5FED, &H6D76, &H7CFF, &H9489, &H8500, &HB79B, &HA612, &HD2AD, &HC324, &HF1BF, &HE036, &H18C1, &H948, &H3BD3, &H2A5A, &H5EE5, &H4F6C, &H7DF7, &H6C7E, _
    &HA50A, &HB483, &H8618, &H9791, &HE32E, &HF2A7, &HC03C, &HD1B5, &H2942, &H38CB, &HA50, &H1BD9, &H6F66, &H7EEF, &H4C74, &H5DFD, &HB58B, &HA402, &H9699, &H8710, &HF3AF, &HE226, &HD0BD, &HC134, &H39C3, &H284A, &H1AD1, &HB58, &H7FE7, &H6E6E, &H5CF5, &H4D7C, _
    &HC60C, &HD785, &HE51E, &HF497, &H8028, &H91A1, &HA33A, &HB2B3, &H4A44, &H5BCD, &H6956, &H78DF, &HC60, &H1DE9, &H2F72, &H3EFB, &HD68D, &HC704, &HF59F, &HE416, &H90A9, &H8120, &HB3BB, &HA232, &H5AC5, &H4B4C, &H79D7, &H685E, &H1CE1, &HD68, &H3FF3, &H2E7A, _
    &HE70E, &HF687, &HC41C, &HD595, &HA12A, &HB0A3, &H8238, &H93B1, &H6B46, &H7ACF, &H4854, &H59DD, &H2D62, &H3CEB, &HE70, &H1FF9, &HF78F, &HE606, &HD49D, &HC514, &HB1AB, &HA022, &H92B9, &H8330, &H7BC7, &H6A4E, &H58D5, &H495C, &H3DE3, &H2C6A, &H1EF1, &HF78)

  2. #2
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: code conversion help

    i think you must use the 'New' keyword like

    CRC_Table = New Array(......)

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: code conversion help

    The problem is that you aren't declaring an array. You are declaring a Variant, which doesn't exist in VB.NET. If you want an Integer array then declare your variable as that type:
    vb.net Code:
    1. Dim crcTable As Integer()
    As for creating the array object, which is a different thing altogether than declaring an array variable, do it like this:
    vb.net Code:
    1. crcTable = New Integer() {&H0, ..., &HF78}
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    97

    Re: code conversion help

    thanks for rep
    now the error is
    Error 1 Bounds can be specified only for the top-level array when initializing an array of arrays.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: code conversion help

    You are now creating a jagged array but you're creating it incorrectly. Your original post says and shows nothing about jagged arrays. If you don't provide us with all the relevant information, like an explanation of what you're trying to achieve and the code you're using to try to achieve it, we can't provide you with a specific solution.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: code conversion help

    i think i can see where you're going wrong. there's a difference between parentheses + curly brackets.
    this is how your declaration should be:

    vb Code:
    1. crcTable = New Integer() { _
    2. &H0, &H1189, &H2312, &H329B, &H4624, &H57AD, &H6536, &H74BF, &H8C48, &H9DC1, &HAF5A, &HBED3, &HCA6C, &HDBE5, &HE97E, &HF8F7, &H1081, &H108, &H3393, &H221A, &H56A5, &H472C, &H75B7, &H643E, &H9CC9, &H8D40, &HBFDB, &HAE52, &HDAED, &HCB64, &HF9FF, &HE876, _
    3. &H2102, &H308B, &H210, &H1399, &H6726, &H76AF, &H4434, &H55BD, &HAD4A, &HBCC3, &H8E58, &H9FD1, &HEB6E, &HFAE7, &HC87C, &HD9F5, &H3183, &H200A, &H1291, &H318, &H77A7, &H662E, &H54B5, &H453C, &HBDCB, &HAC42, &H9ED9, &H8F50, &HFBEF, &HEA66, &HD8FD, &HC974, _
    4. &H4204, &H538D, &H6116, &H709F, &H420, &H15A9, &H2732, &H36BB, &HCE4C, &HDFC5, &HED5E, &HFCD7, &H8868, &H99E1, &HAB7A, &HBAF3, &H5285, &H430C, &H7197, &H601E, &H14A1, &H528, &H37B3, &H263A, &HDECD, &HCF44, &HFDDF, &HEC56, &H98E9, &H8960, &HBBFB, &HAA72, _
    5. &H6306, &H728F, &H4014, &H519D, &H2522, &H34AB, &H630, &H17B9, &HEF4E, &HFEC7, &HCC5C, &HDDD5, &HA96A, &HB8E3, &H8A78, &H9BF1, &H7387, &H620E, &H5095, &H411C, &H35A3, &H242A, &H16B1, &H738, &HFFCF, &HEE46, &HDCDD, &HCD54, &HB9EB, &HA862, &H9AF9, &H8B70, _
    6. &H8408, &H9581, &HA71A, &HB693, &HC22C, &HD3A5, &HE13E, &HF0B7, &H840, &H19C9, &H2B52, &H3ADB, &H4E64, &H5FED, &H6D76, &H7CFF, &H9489, &H8500, &HB79B, &HA612, &HD2AD, &HC324, &HF1BF, &HE036, &H18C1, &H948, &H3BD3, &H2A5A, &H5EE5, &H4F6C, &H7DF7, &H6C7E, _
    7. &HA50A, &HB483, &H8618, &H9791, &HE32E, &HF2A7, &HC03C, &HD1B5, &H2942, &H38CB, &HA50, &H1BD9, &H6F66, &H7EEF, &H4C74, &H5DFD, &HB58B, &HA402, &H9699, &H8710, &HF3AF, &HE226, &HD0BD, &HC134, &H39C3, &H284A, &H1AD1, &HB58, &H7FE7, &H6E6E, &H5CF5, &H4D7C, _
    8. &HC60C, &HD785, &HE51E, &HF497, &H8028, &H91A1, &HA33A, &HB2B3, &H4A44, &H5BCD, &H6956, &H78DF, &HC60, &H1DE9, &H2F72, &H3EFB, &HD68D, &HC704, &HF59F, &HE416, &H90A9, &H8120, &HB3BB, &HA232, &H5AC5, &H4B4C, &H79D7, &H685E, &H1CE1, &HD68, &H3FF3, &H2E7A, _
    9. &HE70E, &HF687, &HC41C, &HD595, &HA12A, &HB0A3, &H8238, &H93B1, &H6B46, &H7ACF, &H4854, &H59DD, &H2D62, &H3CEB, &HE70, &H1FF9, &HF78F, &HE606, &HD49D, &HC514, &HB1AB, &HA022, &H92B9, &H8330, &H7BC7, &H6A4E, &H58D5, &H495C, &H3DE3, &H2C6A, &H1EF1, &HF78}

  7. #7

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    97

    Re: code conversion help

    Quote Originally Posted by .paul. View Post
    i think i can see where you're going wrong. there's a difference between parentheses + curly brackets.
    this is how your declaration should be:

    vb Code:
    1. crcTable = New Integer() { _:check:
    2. &H0, &H1189, &H2312, &H329B, &H4624, &H57AD, &H6536, &H74BF, &H8C48, &H9DC1, &HAF5A, &HBED3, &HCA6C, &HDBE5, &HE97E, &HF8F7, &H1081, &H108, &H3393, &H221A, &H56A5, &H472C, &H75B7, &H643E, &H9CC9, &H8D40, &HBFDB, &HAE52, &HDAED, &HCB64, &HF9FF, &HE876, _
    3. &H2102, &H308B, &H210, &H1399, &H6726, &H76AF, &H4434, &H55BD, &HAD4A, &HBCC3, &H8E58, &H9FD1, &HEB6E, &HFAE7, &HC87C, &HD9F5, &H3183, &H200A, &H1291, &H318, &H77A7, &H662E, &H54B5, &H453C, &HBDCB, &HAC42, &H9ED9, &H8F50, &HFBEF, &HEA66, &HD8FD, &HC974, _
    4. &H4204, &H538D, &H6116, &H709F, &H420, &H15A9, &H2732, &H36BB, &HCE4C, &HDFC5, &HED5E, &HFCD7, &H8868, &H99E1, &HAB7A, &HBAF3, &H5285, &H430C, &H7197, &H601E, &H14A1, &H528, &H37B3, &H263A, &HDECD, &HCF44, &HFDDF, &HEC56, &H98E9, &H8960, &HBBFB, &HAA72, _
    5. &H6306, &H728F, &H4014, &H519D, &H2522, &H34AB, &H630, &H17B9, &HEF4E, &HFEC7, &HCC5C, &HDDD5, &HA96A, &HB8E3, &H8A78, &H9BF1, &H7387, &H620E, &H5095, &H411C, &H35A3, &H242A, &H16B1, &H738, &HFFCF, &HEE46, &HDCDD, &HCD54, &HB9EB, &HA862, &H9AF9, &H8B70, _
    6. &H8408, &H9581, &HA71A, &HB693, &HC22C, &HD3A5, &HE13E, &HF0B7, &H840, &H19C9, &H2B52, &H3ADB, &H4E64, &H5FED, &H6D76, &H7CFF, &H9489, &H8500, &HB79B, &HA612, &HD2AD, &HC324, &HF1BF, &HE036, &H18C1, &H948, &H3BD3, &H2A5A, &H5EE5, &H4F6C, &H7DF7, &H6C7E, _
    7. &HA50A, &HB483, &H8618, &H9791, &HE32E, &HF2A7, &HC03C, &HD1B5, &H2942, &H38CB, &HA50, &H1BD9, &H6F66, &H7EEF, &H4C74, &H5DFD, &HB58B, &HA402, &H9699, &H8710, &HF3AF, &HE226, &HD0BD, &HC134, &H39C3, &H284A, &H1AD1, &HB58, &H7FE7, &H6E6E, &H5CF5, &H4D7C, _
    8. &HC60C, &HD785, &HE51E, &HF497, &H8028, &H91A1, &HA33A, &HB2B3, &H4A44, &H5BCD, &H6956, &H78DF, &HC60, &H1DE9, &H2F72, &H3EFB, &HD68D, &HC704, &HF59F, &HE416, &H90A9, &H8120, &HB3BB, &HA232, &H5AC5, &H4B4C, &H79D7, &H685E, &H1CE1, &HD68, &H3FF3, &H2E7A, _
    9. &HE70E, &HF687, &HC41C, &HD595, &HA12A, &HB0A3, &H8238, &H93B1, &H6B46, &H7ACF, &H4854, &H59DD, &H2D62, &H3CEB, &HE70, &H1FF9, &HF78F, &HE606, &HD49D, &HC514, &HB1AB, &HA022, &H92B9, &H8330, &H7BC7, &H6A4E, &H58D5, &H495C, &H3DE3, &H2C6A, &H1EF1, &HF78}
    thanks for rep but this also not worked for me. error is
    Error 1 Identifier expected.

    i want to calculate crc bytes for data for doing this the total code i have is

    Public Function CreatePacket(Data_Resource() As Byte) As Variant
    Dim Result As Integer, i As Integer, CRC_Table As Variant, CRLo As Byte, CRHi As Byte, CR As Variant
    CRC_Table = Array( _
    &H0, &H1189, &H2312, &H329B, &H4624, &H57AD, &H6536, &H74BF, &H8C48, &H9DC1, &HAF5A, &HBED3, &HCA6C, &HDBE5, &HE97E, &HF8F7, &H1081, &H108, &H3393, &H221A, &H56A5, &H472C, &H75B7, &H643E, &H9CC9, &H8D40, &HBFDB, &HAE52, &HDAED, &HCB64, &HF9FF, &HE876, _
    &H2102, &H308B, &H210, &H1399, &H6726, &H76AF, &H4434, &H55BD, &HAD4A, &HBCC3, &H8E58, &H9FD1, &HEB6E, &HFAE7, &HC87C, &HD9F5, &H3183, &H200A, &H1291, &H318, &H77A7, &H662E, &H54B5, &H453C, &HBDCB, &HAC42, &H9ED9, &H8F50, &HFBEF, &HEA66, &HD8FD, &HC974, _
    &H4204, &H538D, &H6116, &H709F, &H420, &H15A9, &H2732, &H36BB, &HCE4C, &HDFC5, &HED5E, &HFCD7, &H8868, &H99E1, &HAB7A, &HBAF3, &H5285, &H430C, &H7197, &H601E, &H14A1, &H528, &H37B3, &H263A, &HDECD, &HCF44, &HFDDF, &HEC56, &H98E9, &H8960, &HBBFB, &HAA72, _
    &H6306, &H728F, &H4014, &H519D, &H2522, &H34AB, &H630, &H17B9, &HEF4E, &HFEC7, &HCC5C, &HDDD5, &HA96A, &HB8E3, &H8A78, &H9BF1, &H7387, &H620E, &H5095, &H411C, &H35A3, &H242A, &H16B1, &H738, &HFFCF, &HEE46, &HDCDD, &HCD54, &HB9EB, &HA862, &H9AF9, &H8B70, _
    &H8408, &H9581, &HA71A, &HB693, &HC22C, &HD3A5, &HE13E, &HF0B7, &H840, &H19C9, &H2B52, &H3ADB, &H4E64, &H5FED, &H6D76, &H7CFF, &H9489, &H8500, &HB79B, &HA612, &HD2AD, &HC324, &HF1BF, &HE036, &H18C1, &H948, &H3BD3, &H2A5A, &H5EE5, &H4F6C, &H7DF7, &H6C7E, _
    &HA50A, &HB483, &H8618, &H9791, &HE32E, &HF2A7, &HC03C, &HD1B5, &H2942, &H38CB, &HA50, &H1BD9, &H6F66, &H7EEF, &H4C74, &H5DFD, &HB58B, &HA402, &H9699, &H8710, &HF3AF, &HE226, &HD0BD, &HC134, &H39C3, &H284A, &H1AD1, &HB58, &H7FE7, &H6E6E, &H5CF5, &H4D7C, _
    &HC60C, &HD785, &HE51E, &HF497, &H8028, &H91A1, &HA33A, &HB2B3, &H4A44, &H5BCD, &H6956, &H78DF, &HC60, &H1DE9, &H2F72, &H3EFB, &HD68D, &HC704, &HF59F, &HE416, &H90A9, &H8120, &HB3BB, &HA232, &H5AC5, &H4B4C, &H79D7, &H685E, &H1CE1, &HD68, &H3FF3, &H2E7A, _
    &HE70E, &HF687, &HC41C, &HD595, &HA12A, &HB0A3, &H8238, &H93B1, &H6B46, &H7ACF, &H4854, &H59DD, &H2D62, &H3CEB, &HE70, &H1FF9, &HF78F, &HE606, &HD49D, &HC514, &HB1AB, &HA022, &H92B9, &H8330, &H7BC7, &H6A4E, &H58D5, &H495C, &H3DE3, &H2C6A, &H1EF1, &HF78)

    Result = &HFFFF
    For i = 0 To UBound(Data_Resource)

    Result = (Int(Result / 256) And &HFF) Xor CRC_Table((Result Xor Data_Resource(i)) And &HFF)

    Next

    CRHi = (Result Xor &HFF) And &HFF

    CRLo = (Int(Result / 256) Xor &HFF) And &HFF

    CR = Data_Resource

    ReDim Preserve CR(UBound(Data_Resource) + 3)

    CR(UBound(CR) - 2) = CRHi

    CR(UBound(CR) - 1) = CRLo

    CR(UBound(CR)) = &H7E

    CreatePacket = CR

    End Function

  8. #8

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    97

    Re: code conversion help

    searched all over nothing found....
    another solution of the problem is make dll of this function in vb6 is this possibe.
    Last edited by hitesh 2000; May 30th, 2011 at 07:32 AM.

  9. #9
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: code conversion help

    Use [code][/code] or [HIGHLIGHT="vb"][/HIGHLIGHT] tags around your code, it preserves indentation and makes it easier to read.

    Where was the red underline when you got the Identifier Expected error?

    I'm not sure but it looks like there might be a mistake in the VB6 implementation, not a code breaking mistake but a logic error.
    Code:
    Result = &HFFFF '<-- &HFFFF = -1
    For i = 0 To UBound(Data_Resource)
        'Result / 256 works like a right shift of 8 when Result is positive
        'but it does not behave the same when Result is negative
        'It looks to me like this code might have been converted incorrectly in 
        'the first place 
        Result = (Int(Result / 256) And &HFF) Xor CRC_Table((Result Xor Data_Resource(i)) And &HFF)
    Next
    If you want to maintain that behaviour then everything declared as Integer should be declared as Short. This unfortunately will create a problem with the array declare because hex code in Net is always positive so in order to make it work you need to convert all the 2 byte hex codes into the equivalent signed 16 bit numbers (eg &H8C48 becomes -29624). It's easy to do, just print the array out to the immediate window in VB6.

    As already mentioned you need to get rid of the Variants, change them to the appropriate types.
    W o t . S i g

  10. #10

    Thread Starter
    Lively Member
    Join Date
    May 2011
    Posts
    97

    Re: code conversion help

    that is beyond the time limit i have what about the second option.make dll with vb6

  11. #11

    Re: code conversion help

    I'm still trying to figure out why you're using the "Variant" data type in VB.net which, as JMC said, doesn't exist in .NET! It's just kind of funny that you seem to be taking a step back after you take one forward.

    It would help if you told us where the red underline is actually located (since the IDE does that), but I'll take a guess that it has to do with the "Variant" type that it has no idea about.


    I do want to know why you'd rather make the DLL with VB6 when it would be, in my opinion, better and easier to make it in .NET if you're trying to utilize it on the .NET Framework...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width