【问题标题】:MsgBox doesnt work with multiple stringsMsgBox 不适用于多个字符串
【发布时间】:2014-11-13 15:44:24
【问题描述】:

当我使用此代码时:

Dim sessionid = "sessionid = " + """" + TextBox2.Text + """"
Dim steamlogin = "steamLogin = " + """" + TextBox3.Text + """"
Dim steamparental = "steamparental = " + """" + """"
Dim sortextera = "sort = " + """" + """"
MsgBox(SettingsDir, sessionid + steamlogin + steamparental + sortextera, True)

Visual Basics 出现一个错误,指出它无法将其转换为字符串。 有什么帮助吗?

【问题讨论】:

  • 您是否将OPTION STRICT 设置为OnOff?此外,如果您连接字符串,请在 VB.NET 中使用 &,因为 & 是专门为字符串定义的,而不是 +,并且可以减少生成意外转换的机会。..
  • 什么是 SettingsDir 变量?

标签: .net vb.net


【解决方案1】:

MsgBox 需要 MsgBoxStyle 作为第二个参数,而不是字符串。所以这应该有效:

MsgBox(SettingsDir, MsgBoxStyle.Information, sessionid + steamlogin + steamparental + sortextera)

(我也不知道布尔值作为最后一个参数的目的)

我也喜欢:

  • 使用 MessageBox.Show 代替 VB6 MsgBox 与 .NET 兼容
  • 使用& 而不是+ 进行字符串连接,因为& 是专门为字符串定义的,而不是+,这样可以减少产生意外转换的机会
  • 使用String.Format 格式化字符串:

    Dim message = String.Format("sessionid = ""{0}"" steamLogin = ""{1}"" steamparental = ""{2}"" sort = ""{3}""",
                                TextBox2.Text, TextBox3.Text, "", "")
    

【讨论】:

  • 谢谢!你修好了:)
猜你喜欢
  • 2015-01-30
  • 1970-01-01
  • 2017-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-25
  • 2014-07-13
  • 1970-01-01
相关资源
最近更新 更多