VB to .NET

ISSUE #1014

1% statement is not supported.

Recommendations

We recommend to add a method with the body of the label called by the GoSub. This will require to pass all necessary variables as byref parameters in the respective method.

Sample VB6

PrivateSub Form_Load()
  Dim total AsInteger
  GoSub InsideSub
  MsgBox total
  ExitSub
InsideSub:
  For i = 0 To 10
     total = total + i
  Next i
  Return
EndSub

Target VB.NET

PrivateSub Form1_Load(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) HandlesMyBase.Load
  Dim total AsInteger
  'UPGRADE_ISSUE: (1014) GoSub statement is not supported.
  GoSub InsideSub
  MessageBox.Show(CStr(total), Application.ProductName)
  ExitSub
InsideSub:
  For i AsInteger = 0 To 10
    total += i
  Next i
  'UPGRADE_WARNING: (1041) Return has a new behavior.
  Return
EndSub

Expected VB.NET

PrivateSub Form1_Load(ByVal eventSender AsObject, ByVal eventArgs As EventArgs) HandlesMyBase.Load
  Dim total AsInteger
  InsideSub(total)
  MessageBox.Show(CStr(total), Application.ProductName)
EndSub

PrivateSub InsideSub(ByRef total AsInteger)
  For i AsInteger = 0 To 10
    total += i
  Next i
EndSub

Target C#

privatevoid Form1_Load( Object eventSender, EventArgs eventArgs)
{
  int total = 0;
  //UPGRADE_ISSUE: (1014) GoSub statement is not supported.
  //UPGRADE_TODO: (1065) Error handling statement (GoSub) could not be converted properly. A throw statement was generated instead.
  thrownewException("Migration Exception: 'GoSub InsideSub' not supported");
  MessageBox.Show(total.ToString(), Application.ProductName);
  return;
InsideSub:
  for (int i = 0; i <= 10; i++)
  {
    total += i;
  }
  //UPGRADE_WARNING: (1041) Return has a new behavior.
  return ;
}

Expected C#

privatevoid Form1_Load( Object eventSender, EventArgs eventArgs)
{
  int total = 0;
  InsideSub(ref total);
  MessageBox.Show(total.ToString(), Application.ProductName);
}

privatevoid InsideSub(refint total)
{
  for (int i = 0; i <= 10; i++)
  {
    total += i;
  }
}

Talk To An Engineer