用函数简化你的字符串连接语句
'2004/07/27 朱彦志(goodidea) myad@yeah.net
'你是否非常讨厌 用 &;amp; 一大串的连接变量?
'你是否不得不经常使用""与"""" ?
'就好像这样:
'strFilter = strFilter &;amp; " and [" &;amp; strFldname &;amp; "] like """ &;amp; strValue &;amp; """"
'
'strSql ="insert into tblpubStyle (Class,Prop,Value,Type,[Set],memo,flag) values ('" &;amp; _
' ctl.ControlType &;amp; "','" &;amp; _
' prp.Name &;amp; "','" &;amp; _
' prp.Value &;amp; "','" &;amp; _
' prp.Type &;amp; "', " &;amp; _
' 2 &;amp; "," &;amp; _
' "' ', " &;amp; _
' false ")"
'
'strCnn = "Provider=sqloledb;" &;amp; _
' "Data Source=" &;amp; strServerName &;amp; ";" &;amp; _
' "Initial Catalog=" &;amp; strDbname &;amp; ";" &;amp; _
' "User Id=" &;amp; strUid &;amp; ";" &;amp; _
' "Password=" &;amp; strPwd &;amp; ";"
'
'用它,gCombinationString,这个十分简单的函数,让冗长的代码更简洁,增强语句可读性
'以下是它的使用典型形式:
'strFilter = gCombinationString( "$1 and [$2] like ""$3""",strFilter,strFldname,strValue)
'strCnn= gCombinationString("Provider=sqloledb;Data Source=$1;Initial Catalog=$2;User Id=$3;Password=$4;",_
' strServerName ,strDbname ,strUid, strPwd)
'参数个数不限,参数类型不限
' strSql = gCombinationString("insert into tblpubStyle (Class,Prop,Value,Type,[Set],memo,flag) " &;amp; _
' " values ('$1','$2','$3','$4',$5,$6)", _
' ctl.ControlType, prp.Name, prp.Value, prp.Type, 2, False)
'
Const strCharPre = "$"
Dim varItem As Variant
Dim i As Integer
i = 0
For Each varItem In Para
i = i 1
strText = VBA.Replace(strText, strCharPre &;amp; i, varItem)
strText = VBA.Replace(strText, strCharPre &;amp; "\", strCharPre)
Next
gCombinationString = strText
End Function