How to get text and a variable in a messagebox

前端 未结 5 1128
滥情空心
滥情空心 2021-02-07 15:11

I just need to know how to have plain text and a variable in a messagebox.

For example:

I can do this: MsgBox(variable)

And I can do this: <

5条回答
  •  遥遥无期
    2021-02-07 15:57

    As has been suggested, using the string.format method is nice and simple and very readable.

    In vb.net the " + " is used for addition and the " & " is used for string concatenation.

    In your example:

    MsgBox("Variable = " + variable)
    

    becomes:

    MsgBox("Variable = " & variable)
    

    I may have been a bit quick answering this as it appears these operators can both be used for concatenation, but recommended use is the "&", source http://msdn.microsoft.com/en-us/library/te2585xw(v=VS.100).aspx

    maybe call

    variable.ToString()
    

    update:

    Use string interpolation (vs2015 onwards I believe):

    MsgBox($"Variable = {variable}")
    

提交回复
热议问题