WARNING #1068

    <variable> of type <variable type> is being forced to <type>

    Description

    The VBUC typing engine is able to infer the correct data type of undefined or Variant-type variables, and assign them the correct data type. In some scenarios, a variant-type variable is upgraded to a scalar value; this type inference is done over the variable usage and context.

    Recommendations

    This issue doesn't have any recommendations.

    Sample VB6

    Public Sub ForcedToScalar(b As Boolean)
       Dim v As Variant
       If b Then
         Set v = Form1
         MsgBox v / 3
       Else
         Set v = Class1
       End If
       MsgBox v
    End Sub
    
    Public Function Exists(col As Collection, Index As String) As Boolean
        Dim o As Variant
        On Error GoTo Error
            o = col(Index)
    Error:
       MsgBox "Fail Test"
    End Function
    

    Target VB.NET

    Public Sub ForcedToScalar(ByRef b AsBoolean)
       Dim Class1 As Form1
       Dim v As Form1
       If b Then
          v = Me
          'UPGRADE_WARNING: (1068) v of type Form1 is being forced to Double.
          MessageBox.Show(CStr(CDbl(v) / 3), Application.ProductName)
       Else
          v = Class1
       EndIf
       'UPGRADE_WARNING: (1068) v of type Form1 is being forced to String.
       MessageBox.Show(CStr(v),Application.ProductName)
    End Sub
    
    Public Function Exists(ByVal col As OrderedDictionary, ByVal Index As String) As Boolean
       Dim o As Object
    	Try
    		'UPGRADE_WARNING: (1068) col() of type Variant is being forced to Scalar.
    		o = ReflectionHelper.GetPrimitiveValue(col(Index))
    	Catch
    	End Try
    
    	MessageBox.Show("Fail Test", My.Application.Info.Title)
    End Function
    

    Target C#

    public void ForcedToScalar( bool b)
    {
       Form1 Class1 = null;
       Form1 v = null;
       if (b)
       {
          v = Form1.DefInstance;
          //UPGRADE_WARNING: (1068) v of type Form1 is being forced to double.
          MessageBox.Show((((double) v) / 3).ToString(), Application.ProductName);
       } else
       {
          v = Class1;
       }
       //UPGRADE_WARNING: (1068) v of type Form1 is being forced to string.
       MessageBox.Show((string) v, Application.ProductName);
    }
    
    internal static bool Exists(OrderedDictionary col, string Index)
    {
    	object o = null;
    	try
    	{
    		//UPGRADE_WARNING: (1068) col() of type Variant is being forced to Scalar.
    		o = ReflectionHelper.GetPrimitiveValue(col[Index]);
    	}
    	catch
    	{
    	}
    
    	MessageBox.Show("Fail Test", AssemblyHelper.GetTitle(System.Reflection.Assembly.GetExecutingAssembly()));
    	return false;
    }
    

    Download VBUC Free Trial
    Download VBUC Now

    It's time to eradicate VB6
    ROI of eradicating VB6

    8 Proven Tips for
    Planning a Successful Migration

    8 Tips for migration