none
What is the equivalent of array funtion and Isobject RRS feed

  • Question

  • Hi,

    I face this issue while converting my project from vb6 to vb.net. Below is the problematic line,

    IsObject(Array(arrayLimit))                         'This returns false in vb6

    VS2008 has converted this line as follows,

    IsReference(

    Could anyone please help me to solve this issue?
    New Object() {arrayLimit}) = False       'This returns true in vb.net

    Thanks, Karthikeyan.V

    Thursday, May 31, 2012 2:19 PM

Answers

  • IsObject check whether or not variable has meaningful value so equal VB.NET  is to check value against Nothing when you have reference type and against zero value if you have value type. IsReference instead checks if type is reference type that is the instance of the class. Arrays are reference types thats why IsReference returns true although array might not have meaningful value so it's Nothing.

    I think the conversion is wrong because IsObject did check that value of the variable is set and IsReference instead check whether or not variable is reference type. Those who know more about VB6 to VB.NET conversions can verify am I correct or not.

    See following example.

        Sub Main()
            Dim obj() As Object ' reference type
     
            If IsReference(obj) = False Then
                Console.WriteLine("obj is not reference type")
            End If
     
            If obj Is Nothing Then
                Console.WriteLine("obj has no meaningful value, it is Nothing")
            End If
     
            Dim i As Integer ' value type
     
            If IsReference(i) = False Then
                Console.WriteLine("obj is not reference type")
            End If
     
            If IsReference(i) = True Then
                Console.WriteLine("obj has a reference type")
            End If
     
            Console.ReadKey()
     
        End Sub




    Thursday, May 31, 2012 3:45 PM

All replies

  • IsObject check whether or not variable has meaningful value so equal VB.NET  is to check value against Nothing when you have reference type and against zero value if you have value type. IsReference instead checks if type is reference type that is the instance of the class. Arrays are reference types thats why IsReference returns true although array might not have meaningful value so it's Nothing.

    I think the conversion is wrong because IsObject did check that value of the variable is set and IsReference instead check whether or not variable is reference type. Those who know more about VB6 to VB.NET conversions can verify am I correct or not.

    See following example.

        Sub Main()
            Dim obj() As Object ' reference type
     
            If IsReference(obj) = False Then
                Console.WriteLine("obj is not reference type")
            End If
     
            If obj Is Nothing Then
                Console.WriteLine("obj has no meaningful value, it is Nothing")
            End If
     
            Dim i As Integer ' value type
     
            If IsReference(i) = False Then
                Console.WriteLine("obj is not reference type")
            End If
     
            If IsReference(i) = True Then
                Console.WriteLine("obj has a reference type")
            End If
     
            Console.ReadKey()
     
        End Sub




    Thursday, May 31, 2012 3:45 PM
  • Thanks for your immediate reply. This works fine. Let me test this under various scenarios and confirms this as correct fix.

    Thanks, Karthikeyan.V

    Thursday, May 31, 2012 4:25 PM