Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help converting C# to VB [closed]

I used a tool to convert C# to VB. When I run the program in VB I get the following error:

Events cannot be declared with a delegate type that has a return type.

How do I correct this code?

C#:

using System;
[assembly: CLSCompliant(true)]

namespace Link.API
{
  public delegate decimal DecimalStringDelegate(string s);
  public delegate long OrderDelegateStatus(Order o);
  public delegate void LongDelegate(long val);
}

using System;
using System.Collections.Generic;
using System.Text;

namespace Link.API
{
  public interface TLServer
  {
    event LongDelegate newOrderCancelRequest;
    event OrderDelegateStatus newSendOrderRequest;
    string ClientName(int clientnum);
    bool SymbolSubscribed(string sym);

    Basket AllClientBasket { get; }
  }
}

VB.NET:

Imports System.Text
Imports System.Collections.Generic
Imports System
<Assembly: CLSCompliant(True)>

Namespace Link.API
  Public Delegate Function DecimalStringDelegate(ByVal s As String) As Decimal
  Public Delegate Function OrderDelegateStatus(ByVal o As Order) As Long
  Public Delegate Sub LongDelegate(ByVal val As Long)
End Namespace

Namespace Link.API
  Public Interface Server
    Event newOrderCancelRequest As LongDelegate
    Event newSendOrderRequest As OrderDelegateStatus
    Function ClientName(ByVal clientnum As Integer) As String
    Function SymbolSubscribed(ByVal sym As String) As Boolean
    ReadOnly Property AllClientBasket() As Basket
  End Interface
End Namespace
like image 356
user1905155 Avatar asked Mar 07 '13 22:03

user1905155


People also ask

What is the need for conversion of data type in C?

Since,conversion of datatype is implicit type as 'int' is a subset of 'longtype' hence no need to explicitly convert data from one type to another. Compiler will automatically do conversion.

Can you convert data types in C?

Type Casting is basically a process in C in which we change a variable belonging to one data type to another one. In type casting, the compiler automatically changes one data type to another one depending on what we want the program to do.

What is automatic type conversion in C?

Also known as 'automatic type conversion'. Done by the compiler on its own, without any external trigger from the user. Generally takes place when in an expression more than one data type is present. In such condition type conversion (type promotion) takes place to avoid loss of data.

How many types of conversions are there in C?

In this case, the double value is automatically converted to integer value 34. This type of conversion is known as implicit type conversion. In C, there are two types of type conversion: Implicit Conversion.


1 Answers

As the error alludes to, VB does not support events that use a delegate with a return type. So you can't convert the code directly. One workaround would be to change the delegate to use a ByRef parameter instead:

Public Delegate Sub DecimalStringDelegate(ByVal s As String, ByRef retVal as Decimal)
Public Delegate Sub OrderDelegateStatus(ByVal o As Order, ByRef retVal As Long)
like image 57
D Stanley Avatar answered Oct 12 '22 23:10

D Stanley