从C#到Vb.Net的代码转换 [英] Code Conversion from C# to Vb.Net

查看:68
本文介绍了从C#到Vb.Net的代码转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。



我试图将C#代码转换为vb.net。我尝试了C#代码并且它在控制台上输出成功,我试图复制它并将其转换为vb.net但输出应该在文本框上,但没有输出,也没有错误。你可以帮帮我。



C#代码:



 使用系统; 
使用 MT4API;

class 计划
{
静态 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( 按任意键......);
Console.ReadKey();
dde.Unubscribe(symbol);
}


私有 静态 void MT_OnQuote( object sender,QuoteEventArgs args)
{
Console.WriteLine(args.Symbol + + args.Bid + + args.Ask);
}

}







VB.Net代码:

 进口 MT4API 

公开 Form1
私有 Sub Form1_Load( ByVal sender As System。对象 ByVal e As System.EventArgs)句柄 MyBase .Load
尝试
Dim 符号作为 字符串 = EURUSD
Dim dde ​​作为 MT4DDE( cms
AddHandler dde.OnQuote, AddressOf MT_OnQuote
dde.Connect()
dde.Subscribe(symbol)
TextBox1.Text = 按任意键 + vbCrLf
dde.Unubscribe(symbol)
Catch ex 作为异常
TextBox1.Text = TextBox1.Text + ex.Message
结束 尝试

结束 Sub

私有 Sub MT_OnQuote( By Val 发​​件人作为 对象 ByVal args As QuoteEventArgs)
TextBox1.Text = TextBox1.Text + args.Symbol + vbTab + args.Bid + vbTab + args.Ask + vbCrLf
结束 Sub

结束 班级





非常感谢。

解决方案

每次要从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 < span class =code-keyword>字符串 = EURUSD
Dim 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[^]


这篇关于从C#到Vb.Net的代码转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆