Click here to Skip to main content
15,916,835 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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:
VB
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.
Posted
Comments
Mahesh Bailwal 9-Oct-13 1:32am    
Did you debug it?

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
 
Share this answer
 
Try with this web site


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


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
 
Share this answer
 
v2
Comments
Member 9363513 9-Oct-13 2:06am    
I have already converted the C# code to vb.net using the console to have an output and it works fine but when i tried to have the output on a form with textbox as an output there is no result.
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900