Jack
Jack

Reputation: 5

MsgBox doesnt work with multiple strings

When i use this code:

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 comes up with an error saying it can't convert this to a string. Any help?

Upvotes: 0

Views: 70

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460208

MsgBox expects a MsgBoxStyle as the second parameter, not a string. So this should work:

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

(i also don't know the purpose for the boolean as last parameter)

I also prefer:

  • using MessageBox.Show instead of the VB6 MsgBox to be .NET compatible
  • using & instead of + for string concatenation because & is defined exclusively for strings as opposed to + and reduces your chances of generating an unintended conversion
  • using String.Format to format strings:

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

Upvotes: 5

Related Questions