Click here to Skip to main content
15,924,367 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have experienced a error from a converter code from C# I converted it to VB because I am not a C# programmer, here is the code:
  Private Sub sendTrace()
      Dim pingSender As New Ping()
      Dim options As New PingOptions()
      Dim ttl As Integer = 1
      options.DontFragment = True
      Dim IPs As IPAddress() = Nothing
      Try
          IPs = Dns.GetHostEntry(hostbox.Text.Trim()).AddressList
      Catch e As SocketException
          Update_Button(sendit, True)
          Update_Button(stopit, False)
          SetText(results, e.Message + vbCr & vbLf)
          Return
      End Try

      Dim hops As Integer = 0, timeout As Integer = 0
      Try
          hops = Convert.ToInt32(databox.Text.Trim())
          timeout = Convert.ToInt32(databox2.Text.Trim())
      Catch e As FormatException
          Update_Button(sendit, True)
          Update_Button(stopit, False)
          SetText(results, e.Message + vbCr & vbLf)
          Return
      End Try

      SetText(results, "-----------------------------------" & vbCr & vbLf & "Tracing route to " + hostbox.Text + " [" + IPs(0) + "]" & vbCr & vbLf)  < ERROR HERE

      While traceing AndAlso ttl <= hops
          Dim reply As PingReply = Nothing
          options.Ttl = ttl
'   ...............................................deleted code. because too long
  End Sub


The error is
VB
<pre>
       SetText(results, "-----------------------------------" &amp; vbCr &amp; vbLf &amp; "Tracing route to " + hostbox.Text + " [" + IPs(0) + "]" &amp; vbCr &amp; vbLf)
Error 4 Operator '&' is not defined for types 'String' and 'System.Net.IPAddress'.
Posted

Either
C#
SetText(results, "-----------------------------------" & vbCr & vbLf & "Tracing route to " + hostbox.Text + " [" & IPs(0) & "]" & vbCr & vbLf) 

OR
C#
SetText(results, "-----------------------------------" & vbCr & vbLf & "Tracing route to " + hostbox.Text + " [" + IPs(0).Tostring() + "]" & vbCr & vbLf) 

Happy coding!
:)
 
Share this answer
 
ensure that that value of IPs(0) is string.
 
Share this answer
 
While replacing '& vbCr' with Environment.NewLine : code generator might created extra lines

" & vbCr & vbLf &"




write it as follows


C#
SetText (results, "---------------" + Environment.NewLine   +"Tracing route to"  + hostbox.Text + " [" + IPs(0) + "]");

or

C#
string value = String.Format( "-----------{0} Tracing route to {1} [{2}]",Environment.NewLine,hostbox.Text, IPs(0));

SetText (results, value);
 
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