Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I tried to convert this but it shows me many errors can someone try to convert it, TY.
VB
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Drawing
Imports System.Runtime.Serialization.Formatters.Binary
Public Class Form1
    Dim client As New TcpClient
    Dim server As New TcpListener(8085)
    Dim nstream As NetworkStream
    Dim listening As New Thread(AddressOf Listen)
    Dim getImage As New Thread(AddressOf receiveImage)
    Private Sub receiveImage()
        Dim bf As New BinaryFormatter
        While client.Connected = True
            nstream = client.GetStream
            picturebox1.Image = bf.Deserialize(nstream)
        End While
    End Sub
    Private Sub Listen()
        While client.Connected = False
            server.Start()
            client = server.AcceptTcpClient
        End While
        getImage.Start()
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        listening.Start()
        Button1.Visible = False
    End Sub
End Class
Posted
Updated 9-Feb-15 4:56am
v2
Comments
Kuthuparakkal 9-Feb-15 11:05am    
If it's that small; why don't you attempt to write it in C# ?
Richard MacCutchan 9-Feb-15 11:10am    
If you showed the code you have, and explained the errors, then it would be easier to help you.

You can do such translation automatically. Please see my past answer: Code Interpretation, C# to VB.NET[^].

—SA
 
Share this answer
 
I have converted it by
SharpDevelop[^]:

Quote:
SharpDevelop is the open-source IDE for the .NET platform. Write applications in languages including C#, VB.NET, F#, IronPython and IronRuby, as well as target rich and reach: Windows Forms or WPF, as well as ASP.NET MVC and WCF. It starts from USB drives, supports read-only projects, comes with integrated unit and performance testing tools, Git, NuGet and a lot more features that make you productive as a developer.


C#
 using System.IO;
 using System.Net;
 using System.Net.Sockets;
 using System.Threading;
 using System.Drawing;
 using System.Runtime.Serialization.Formatters.Binary;

 public class Form1
 {
	TcpClient client = new TcpClient();
	TcpListener server = new TcpListener(8085);
	NetworkStream nstream;
	Thread listening = new Thread(Listen);
	Thread getImage = new Thread(receiveImage);
	private void receiveImage()
	{
		BinaryFormatter bf = new BinaryFormatter();
		while (client.Connected == true) {
			nstream = client.GetStream;
			picturebox1.Image = bf.Deserialize(nstream);
		}
	}
	private void Listen()
	{
		while (client.Connected == false) {
			server.Start();
			client = server.AcceptTcpClient;
		}
		getImage.Start();
	}

	private void Button1_Click(System.Object sender, System.EventArgs e)
	{
		listening.Start();
		Button1.Visible = false;
	}
}
 
Share this answer
 
v2
I used (which you can also) Telerik Converter[^] to convert this code to C#, or any C# code to VB.NET.

The following code was provided, which is simple enough to understand and then use.

C#
// I believe there were some libraries that are only present in VB.NET
// So, a reference to Microsoft.VisualBasic might have been required
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Drawing;
using System.Runtime.Serialization.Formatters.Binary;
public class Form1
{
	TcpClient client = new TcpClient();
	TcpListener server = new TcpListener(8085);
	NetworkStream nstream;
	Thread listening = new Thread(Listen);
	Thread getImage = new Thread(receiveImage);
	private void receiveImage()
	{
		BinaryFormatter bf = new BinaryFormatter();
		while (client.Connected == true) {
			nstream = client.GetStream;
			picturebox1.Image = bf.Deserialize(nstream);
		}
	}
	private void Listen()
	{
		while (client.Connected == false) {
			server.Start();
			client = server.AcceptTcpClient;
		}
		getImage.Start();
	}

	private void Button1_Click(System.Object sender, System.EventArgs e)
	{
		listening.Start();
		Button1.Visible = false;
	}
}


You can also use that converter to convert your VB.NET code to C# code.
 
Share this answer
 
v2
Comments
tome3 9-Feb-15 12:04pm    
Yes but the problem is that it shows some errors in c# that in vb does not show
ex: its not posible "picturebox1.Image = bf.Deserialize(nstream);" in c# in vb is posible
Afzaal Ahmad Zeeshan 9-Feb-15 12:09pm    
That is because that assembly and code was present in the VB.NET, one thing you can do is open the Reference window (inside your solution directory) and check the Microsoft.VisualBasic assembly, to include it to your project. Then it will be consumable by your project. Otherwise, you would have to change it to C# code (and the assembly too).
tome3 10-Feb-15 7:43am    
Thanks.

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