简体   繁体   English

如何在 VB msgbox()...中使用 \n 换行?

[英]How to use \n new line in VB msgbox() ...?

What is the alternative to \n (for new line) in a MsgBox() ? MsgBox()\n (换行)的替代方法是什么?

  • for VB: vbCrLf or vbNewLine 对于VB: vbCrLfvbNewLine
  • for VB.NET: Environment.NewLine or vbCrLf or Constants.vbCrLf 对于VB.NET: Environment.NewLinevbCrLfConstants.vbCrLf

Info on VB.NET new line: http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx 关于VB.NET新行的信息: http//msdn.microsoft.com/en-us/library/system.environment.newline.aspx

The info for Environment.NewLine came from Cody Gray and J Vermeire Environment.NewLine的信息来自Cody GrayJ Vermeire

These are the character sequences to create a new line: 这些是创建新行的字符序列:

  • vbCr is the carriage return (return to line beginning), vbCr是回车(返回行开头),

  • vbLf is the line feed (go to next line) vbLf是换行符(转到下一行)

  • vbCrLf is the carriage return / line feed (similar to pressing Enter) vbCrLf是回车符/换行符(类似于按Enter键)

I prefer vbNewLine as it is system independent ( vbCrLf may not be a true new line on some systems) 我更喜欢vbNewLine因为它与系统无关 (在某些系统上vbCrLf可能不是真正的新行)

尝试使用vbcrlf换行

msgbox "This is how" & vbcrlf & "to get a new line"

添加vbNewLine为:

"text1" & vbNewLine & "text2"

An alternative to Environment.NewLine is to use : Environment.NewLine的替代方法是使用:

Regex.Unescape("\n\tHello World\n")

from System.Text.RegularExpressions 来自System.Text.RegularExpressions

This allows you to escape Text without Concatenating strings as you can in C#, C, java 这允许您在没有连接字符串的情况下转义Text,就像在C#,C,java中一样

正确的格式是:

"text1" + vbNewLine + "text2"

Use the command "vbNewLine" 使用命令“vbNewLine”

Example

Hello & vbNewLine & "World"

will show up as Hello on one line and World on another 将在一行显示为Hello,在另一行显示为World

You can use Environment.NewLine OR vbCrLF OR vbNewLine您可以使用Environment.NewLinevbCrLFvbNewLine

MsgBox($"Hi!{Environment.NewLine}I'M HERE")
Module MyHelpers
    <Extension()>
    Public Function UnEscape(ByVal aString As String) As String

       Return Regex.Unescape(aString)

    End Function
End Module

Usage: 用法:

console.writeline("Ciao!\n".unEscape)

在我这边,我创建了一个子MyMsgBox,在ControlChars.NewLine的提示符中替换\\ n

msgbox "This is the first line" & vbcrlf & "and this is the second line"

或者在.NET msgbox "This is the first line" & Environment.NewLine & "and this is the second line"

do not forget to set the Multiline property to true in textbox不要忘记在文本框中将 Multiline 属性设置为 true

您可以使用回车符(Chr(13)),换行符(Chr(10))也可以

MsgBox "Message Name: " & objSymbol1.Name & Chr(13) & "Value of BIT-1: " & (myMessage1.Data(1)) & Chr(13) & "MessageCount: " & ReceiveMessages.Count

A lot of the stuff above didn't work for me. 上面的很多东西都不适合我。 What did end up working is 最终工作的是什么

Chr(13)

这对我MessageBox.Show("YourString" & vbcrlf & "YourNewLineString")MessageBox.Show("YourString" & vbcrlf & "YourNewLineString")

消息框必须以文本结束,而不是以变量结尾

msgbox("your text here" & Environment.NewLine & "more text") is the easist way. msgbox(“你的文字在这里”和Environment.NewLine和“更多文字”)是最简单的方式。 no point in making your code harder or more ocmplicated than you need it to be... 没有必要让你的代码比你需要的更难或更复杂......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM