且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从C#到Vb.Net的代码转换

更新时间:2022-10-16 12:06:41

每次要从VB.NET转换到C#或返回时,问这样的问题都不好。它可以使用一些离线工具自动完成;特别注意由精彩的开源工具ILSpy提供的最全面的离线方法。请参阅我过去的答案以获取更多详细信息:

C#对VB.NET的COde行解释 [ ^ ],

需要将vb代码转换为c# [ ^ ],

FixedPage到ContentPage将c#代码转换为vb.net [ ^ ]。



-SA


试试这个网站





http://www.developerfusion.com/tools/ convert / csharp-to-vb / [ ^ ]





 进口 MT4API 

班级计划
私人 共享 Sub Main(args As 字符串())
Dim 符号 As 字符串 = EURUSD
Dim pan> dde ​​作为 MT4DDE(
dde.OnQuote + = EventHandler( Of QuoteEventArgs)( AddressOf MT_OnQuote)
dde.Connect()
dde.Subscribe(symbol)
Console.WriteLine( 按任意键...
Console.ReadKey()
dde.Unubscribe(symbol)
End Sub


私有 共享 Sub MT_OnQuote(发件人作为 对象,args 作为 QuoteEventArgs)
Console.Wr iteLine(Convert.ToString(args.Symbol)& & Convert.ToString(args.Bid)& & Convert.ToString(args.Ask))
结束 Sub

结束


你不能指望100%转换,你必须自己做一些手动更改。可能你可以使用其他转换器进行更接近的转换。

.NET代码转换 - 转换代码 [ ^

Hi Guys.

I've tried to convert a C# code to vb.net. I tried the C# code and it was successful with an output on a console, i have tried to copy it and convert it into vb.net but the output should be on a textbox but there is no output and there is no error either. Can you please help me with this.

C# code:

using System;
using MT4API;

class Program
{
  static void Main(string[] args)
  {
    string symbol = "EURUSD";
    MT4DDE dde = new MT4DDE("");
    dde.OnQuote += new EventHandler<QuoteEventArgs>(MT_OnQuote);
    dde.Connect();
    dde.Subscribe(symbol);
    Console.WriteLine("Press any key...");
    Console.ReadKey();
    dde.Unubscribe(symbol);
  }


  private static void MT_OnQuote(object sender, QuoteEventArgs args)
  {
    Console.WriteLine(args.Symbol + " " + args.Bid + " " + args.Ask);
  }

}




VB.Net Code:

Imports MT4API

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            Dim symbol As String = "EURUSD"
            Dim dde As New MT4DDE("cms")
            AddHandler dde.OnQuote, AddressOf MT_OnQuote
            dde.Connect()
            dde.Subscribe(symbol)
            TextBox1.Text = "Press any key" + vbCrLf
            dde.Unubscribe(symbol)
        Catch ex As Exception
            TextBox1.Text = TextBox1.Text + ex.Message
        End Try
        
    End Sub

    Private Sub MT_OnQuote(ByVal sender As Object, ByVal args As QuoteEventArgs)
        TextBox1.Text = TextBox1.Text + args.Symbol + vbTab + args.Bid + vbTab + args.Ask + vbCrLf
    End Sub

End Class



Thank you very much.

It's not good to ask such question each time you want to translate from VB.NET to C# or back. It can be done automatically, using some on-line of off-line tools; pay special attention for the most comprehensive off-line method provided by the wonderful open-source tool ILSpy. Please see my past answers for further detail:
COde Line Interpretatio of C# to VB.NET[^],
Need to convert vb code to c#[^],
FixedPage to ContentPage convert c# code into vb.net[^].

—SA


Try with this web site


http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]


Imports MT4API

Class Program
    Private Shared Sub Main(args As String())
        Dim symbol As String = "EURUSD"
        Dim dde As New MT4DDE("")
        dde.OnQuote += New EventHandler(Of QuoteEventArgs)(AddressOf MT_OnQuote)
        dde.Connect()
        dde.Subscribe(symbol)
        Console.WriteLine("Press any key...")
        Console.ReadKey()
        dde.Unubscribe(symbol)
    End Sub


    Private Shared Sub MT_OnQuote(sender As Object, args As QuoteEventArgs)
        Console.WriteLine(Convert.ToString(args.Symbol) & " " & Convert.ToString(args.Bid) & " " & Convert.ToString(args.Ask))
    End Sub

End Class


You can't expect 100% conversion, you have to do some manual changes yourself. Possibly you could get some more closer conversion using other convertors.
.NET Code Conversion - Convert your code[^]