奇怪的错误&不是一个... [英] Strange error & is not a...

查看:90
本文介绍了奇怪的错误&不是一个...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了来自C#转换器代码的错误,我将其转换为VB,因为我不是C#程序员,这里是代码:

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

<pre>
       SetText(results, "-----------------------------------" &amp; vbCr &amp; vbLf &amp; "Tracing route to " + hostbox.Text + " [" + IPs(0) + "]" &amp; vbCr &amp; vbLf)

错误4未对类型'String'和'System.Net定义运算符'&'。 IPAddress'。

Error 4 Operator '&' is not defined for types 'String' and 'System.Net.IPAddress'.

推荐答案



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






OR

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



快乐编码!

:)


Happy coding!
:)


确保IPs(0)的值是字符串。
ensure that that value of IPs(0) is string.


替换'&带有 Environment.NewLine 的vbCr':代码生成器可能会创建额外的行



& vbCr& vbLf &








写如下





While replacing '& vbCr' with Environment.NewLine : code generator might created extra lines

" & vbCr & vbLf &"




write it as follows


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








or

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

SetText (results, value);


这篇关于奇怪的错误&amp;不是一个...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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