M
monemas
Guest
hi
I got the C Sharp code
I want To convert to VB.NET
get 2 error
1- ReceiveMsg' is not an event of 'eserver1.Form1'.
2-Function '<anonymous method>' doesn't return a value on all code paths
use this web to convert
Code Converter C# to VB and VB to C# – Telerik
code c#
public EventHandler ReceiveMsg ;
DateTime LastReceive;
InitializeComponent();
ReceiveMsg += ReceiveMsg_Handler;
LastReceive = DateTime.Now;
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList.Where(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
.FirstOrDefault();
lblip.Text = ipAddress.ToString();
private void ReceiveMsg_Handler(object sender, EventArgs e)
{
LastReceive = DateTime.Now;
Timer1_Tick(null, null);
if (sender.ToString().Contains("ping"))
return;
var Barcode = sender.ToString().Split('-');
txtbarcode.Invoke((MethodInvoker)delegate {
// Running on the UI thread
txtbarcode.Text = Barcode[0];
txtname.Text = Barcode[1].Substring(0, Barcode[1].IndexOf("<EOF>"));
});
SendKeys.SendWait(Barcode[0]);
}
Thread Serverthread;
private void Timer1_Tick(object sender, EventArgs e)
{
bool res = DateTime.Now - LastReceive >= TimeSpan.FromSeconds(2);
lblStatus.Invoke((MethodInvoker)delegate
{
lblStatus.Text = res ? "Disconnected": "Connected";
lblStatus.ForeColor = res ? Color.Red : Color.Green;
});
return;
}
'===================================
vb.net convert
Public ReceiveMsg As EventHandler
Private LastReceive As DateTime
Public Sub New()
InitializeComponent()
AddHandler ReceiveMsg, AddressOf ReceiveMsg_Handler ' error1
LastReceive = DateTime.Now
Dim ipHostInfo As IPHostEntry = Dns.GetHostEntry(Dns.GetHostName())
Dim ipAddress As IPAddress = ipHostInfo.AddressList.Where(Function(x) x.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork).FirstOrDefault()
lblip.Text = ipAddress.ToString()
End Sub
Public Sub ReceiveMsg_Handler(ByVal sender As Object, ByVal e As EventArgs)
LastReceive = DateTime.Now
Timer1_Tick(Nothing, Nothing)
If sender.ToString().Contains("ping") Then Return
Dim Barcode = sender.ToString().Split("-"c)
txtbarcode.Invoke(CType(Function()
txtbarcode.Text = Barcode(0)
txtname.Text = Barcode(1).Substring(0, Barcode(1).IndexOf("<EOF>"))
End Function, MethodInvoker))
SendKeys.SendWait(Barcode(0))
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Dim res As Boolean = DateTime.Now - LastReceive >= TimeSpan.FromSeconds(2)
lblStatus.Invoke(CType(Function()
lblStatus.Text = If(res, "Disconnected", "Connected")
lblStatus.ForeColor = If(res, Color.Red, Color.Green)
End Function, MethodInvoker))
Return
End Sub
Continue reading...
I got the C Sharp code
I want To convert to VB.NET
get 2 error
1- ReceiveMsg' is not an event of 'eserver1.Form1'.
2-Function '<anonymous method>' doesn't return a value on all code paths
use this web to convert
Code Converter C# to VB and VB to C# – Telerik
code c#
public EventHandler ReceiveMsg ;
DateTime LastReceive;
InitializeComponent();
ReceiveMsg += ReceiveMsg_Handler;
LastReceive = DateTime.Now;
IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList.Where(x => x.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
.FirstOrDefault();
lblip.Text = ipAddress.ToString();
private void ReceiveMsg_Handler(object sender, EventArgs e)
{
LastReceive = DateTime.Now;
Timer1_Tick(null, null);
if (sender.ToString().Contains("ping"))
return;
var Barcode = sender.ToString().Split('-');
txtbarcode.Invoke((MethodInvoker)delegate {
// Running on the UI thread
txtbarcode.Text = Barcode[0];
txtname.Text = Barcode[1].Substring(0, Barcode[1].IndexOf("<EOF>"));
});
SendKeys.SendWait(Barcode[0]);
}
Thread Serverthread;
private void Timer1_Tick(object sender, EventArgs e)
{
bool res = DateTime.Now - LastReceive >= TimeSpan.FromSeconds(2);
lblStatus.Invoke((MethodInvoker)delegate
{
lblStatus.Text = res ? "Disconnected": "Connected";
lblStatus.ForeColor = res ? Color.Red : Color.Green;
});
return;
}
'===================================
vb.net convert
Public ReceiveMsg As EventHandler
Private LastReceive As DateTime
Public Sub New()
InitializeComponent()
AddHandler ReceiveMsg, AddressOf ReceiveMsg_Handler ' error1
LastReceive = DateTime.Now
Dim ipHostInfo As IPHostEntry = Dns.GetHostEntry(Dns.GetHostName())
Dim ipAddress As IPAddress = ipHostInfo.AddressList.Where(Function(x) x.AddressFamily = System.Net.Sockets.AddressFamily.InterNetwork).FirstOrDefault()
lblip.Text = ipAddress.ToString()
End Sub
Public Sub ReceiveMsg_Handler(ByVal sender As Object, ByVal e As EventArgs)
LastReceive = DateTime.Now
Timer1_Tick(Nothing, Nothing)
If sender.ToString().Contains("ping") Then Return
Dim Barcode = sender.ToString().Split("-"c)
txtbarcode.Invoke(CType(Function()
txtbarcode.Text = Barcode(0)
txtname.Text = Barcode(1).Substring(0, Barcode(1).IndexOf("<EOF>"))
End Function, MethodInvoker))
SendKeys.SendWait(Barcode(0))
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As EventArgs) Handles Timer1.Tick
Dim res As Boolean = DateTime.Now - LastReceive >= TimeSpan.FromSeconds(2)
lblStatus.Invoke(CType(Function()
lblStatus.Text = If(res, "Disconnected", "Connected")
lblStatus.ForeColor = If(res, Color.Red, Color.Green)
End Function, MethodInvoker))
Return
End Sub
Continue reading...