locked
VB6 to VB.NET problem RRS feed

  • Question

  • VB 6:

    Dim iElementType as Integer

    Dim iAns as integer

    iAns = Format (iElementType ,"00")

    After migration,

    VB.NET,

    Dim iElementType as short

    Dim iAns as short

    iAns = VB6.Format (iElementType ,"00")

    Both or equal? and 'Format','FormatNumber'  functions are in vb.net ll provide also same answer?

    Which one is correct?

    One more doubt....

    After migration , one step contains vb6.Copyarray() ...what is it? Which one in vb6 is equivalent for vb6.copyarray() ?

    Thanks.... 

    Friday, December 20, 2013 1:02 PM

Answers

  • Dim iElementType as Integer
    Dim iAns as integer
    iAns = Format (iElementType ,"00")
    iAns = VB6.Format (iElementType ,"00")

    this doesn't do anything, and if you put option strict on you will see that it won't even compile, since it tries to put string into an integer.

    so correct would be

    iAns = iElementType

    As for

    After migration , one step contains vb6.Copyarray() ...what is it? Which one in vb6 is equivalent for vb6.copyarray() ?

    I would need to see some more code to give you an answer


    • Edited by Rbie Friday, December 20, 2013 2:37 PM
    • Proposed as answer by Elmar Boye Friday, December 20, 2013 4:12 PM
    • Marked as answer by Ganesan C Monday, December 23, 2013 6:34 AM
    Friday, December 20, 2013 2:37 PM
  • Hi,

    as RBie already said, your code is a more a Donothing. In VB 6 the formatted value is implicitly converted to an (16-bit) Integer again, and the formatting is lost.

    Any formatting should only be done if the target is a string variable. The preferred methods are the .NET built-in formatting options, see Formatting Types (ff.). For example:

    Dim iElementType as Short = 0
    Dim sAns as String = iElementType.ToString("00")

    CopyArray can be done using Array.Copy or the CopyTo method. The CopyTo Method is also implemented by other collections like List<T> as part of the ICollection / ICollection(T) interface.

    Regards, Elmar

    • Marked as answer by Ganesan C Monday, December 23, 2013 6:34 AM
    Friday, December 20, 2013 4:10 PM
  • Try to avoid the VB6 compatibility namespace as it will be more and more removed in future frameworks.

    (For those C# developers who get then direct conclusions, no that is not the VB namespace)

    You also can avoid the format. The overloaded short.ToString has everything in it to get things done.

    http://msdn.microsoft.com/en-us/library/ee436731.aspx


    Success
    Cor

    • Marked as answer by Ganesan C Monday, December 23, 2013 6:34 AM
    Friday, December 20, 2013 5:10 PM

All replies

  • Dim iElementType as Integer
    Dim iAns as integer
    iAns = Format (iElementType ,"00")
    iAns = VB6.Format (iElementType ,"00")

    this doesn't do anything, and if you put option strict on you will see that it won't even compile, since it tries to put string into an integer.

    so correct would be

    iAns = iElementType

    As for

    After migration , one step contains vb6.Copyarray() ...what is it? Which one in vb6 is equivalent for vb6.copyarray() ?

    I would need to see some more code to give you an answer


    • Edited by Rbie Friday, December 20, 2013 2:37 PM
    • Proposed as answer by Elmar Boye Friday, December 20, 2013 4:12 PM
    • Marked as answer by Ganesan C Monday, December 23, 2013 6:34 AM
    Friday, December 20, 2013 2:37 PM
  • Hi,

    as RBie already said, your code is a more a Donothing. In VB 6 the formatted value is implicitly converted to an (16-bit) Integer again, and the formatting is lost.

    Any formatting should only be done if the target is a string variable. The preferred methods are the .NET built-in formatting options, see Formatting Types (ff.). For example:

    Dim iElementType as Short = 0
    Dim sAns as String = iElementType.ToString("00")

    CopyArray can be done using Array.Copy or the CopyTo method. The CopyTo Method is also implemented by other collections like List<T> as part of the ICollection / ICollection(T) interface.

    Regards, Elmar

    • Marked as answer by Ganesan C Monday, December 23, 2013 6:34 AM
    Friday, December 20, 2013 4:10 PM
  • Try to avoid the VB6 compatibility namespace as it will be more and more removed in future frameworks.

    (For those C# developers who get then direct conclusions, no that is not the VB namespace)

    You also can avoid the format. The overloaded short.ToString has everything in it to get things done.

    http://msdn.microsoft.com/en-us/library/ee436731.aspx


    Success
    Cor

    • Marked as answer by Ganesan C Monday, December 23, 2013 6:34 AM
    Friday, December 20, 2013 5:10 PM