我正在尝试在vb6中进行串联。不支持运算符+ =,我想做下面的代码。我想在程序中处理更多代码时在文本框中添加更多字符串。谁能建议将+ =更改为什么?我知道&可以在将一个字符串添加到另一个字符串时使用它,但这是我在此工作的示例,似乎不合适。
谢谢。
If (strHomeNo <> "") Then
txtPhoneNums = "Home: " + strHomeNo
End If
If (strMobileNo <> "") Then
txtPhoneNums += "Mobile: " + strMobileNo
End If
If (strWorkNo <> "") Then
txtPhoneNums += "Work: " + strWorkNo
End If
If (txtPhoneNums <> "") Then
txtPhoneNums.ForeColor = vbBlack
txtPhoneNums.FontBold = False
End If
Else
txtPhoneNums.Text = "NO CONTACT DETAILS"
txtPhoneNums.ForeColor = vbRed
txtPhoneNums.FontBold = True
将:
txtPhoneNums = txtPhoneNums & "Work: " & strWorkNo
不起作用?
在VB6中,按照您所说的,用&
运算符连接字符串。我不记得有一个简写&=
(已经有一段时间了),所以您需要:
txtPhoneNums = txtPhoneNums & "Mobile: " & strMobileNo
不要以为有更好的方法。
@@ David和@Brant的答案正确。但是,如果您发现自己做了很多串联操作,则可以构建一个类来使事情变得更容易。类似于:txtPhoneNums.Add(“ Mobile:”,strMobileNo)。我用一个来构建我的SQL语句。
VB6使用“&”连接字符串