向 VBA/VB6 添加换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27067331/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add newline to VBA/VB6
提问by Gerhard Powell
I want to concat two strings with a linebreak between them.
我想连接两个字符串,它们之间有一个换行符。
st = "Line 1" + newline + "Line2"
How do I add a newline to VBA/VB6?
如何向 VBA/VB6 添加换行符?
回答by Gerhard Powell
VB has built-in constants for newlines:
VB 具有用于换行的内置常量:
vbCr= Chr$(13) = CR (carriage-return character) - used by Mac OS and Apple II family
vbCr= Chr$(13) = CR(回车符) - Mac OS 和 Apple II 系列使用
vbLf= Chr$(10) = LF (line-feed character) - used by Linux and Mac OS X
vbLf= Chr$(10) = LF(换行符) - Linux 和 Mac OS X 使用
vbCrLf= Chr$(13) & Chr$(10) = CRLF (carriage-return followed by line-feed) - used by Windows
vbCrLf= Chr$(13) & Chr$(10) = CRLF(回车后换行)- 由 Windows 使用
vbNewLine= the same as vbCrLf
vbNewLine= 一样 vbCrLf
回答by Gajanan Chitare
Use this code between to word " & vbCrLf & "using this next word displays on next line
在单词“ & vbCrLf & ”之间使用此代码, 使用下一个单词显示在下一行
回答by AryanSonwatikar
There are actually two ways if doing this:
如果这样做,实际上有两种方法:
1) st= "Line 1" + vbCrLf + "Line 2"
1)st=“第1行”+vbCrLf+“第2行”
2) st= "Line 1" + vbNewLine+ "Line 2"
2)st=“第1行”+vbNewLine+“第2行”
These even work for message boxes(and all other places where Strings are used).
这些甚至适用于消息框(以及所有其他使用字符串的地方)。

