'2004/07/27 朱彥志(goodidea) [email protected]
'你是否非常討厭 用 & 一大串的連接變量?
'你是否不得不經常使用""與"""" ?
'就好像這樣:
'strfilter = strfilter & " and [" & strfldname & "] like """ & strvalue & """"
'
'strsql ="insert into tblpubstyle (class,prop,value,type,[set],memo,flag) values ('" & _
' ctl.controltype & "','" & _
' prp.name & "','" & _
' prp.value & "','" & _
' prp.type & "', " & _
' 2 & "," & _
' "' ', " & _
' false ")"
'
'strcnn = "provider=sqloledb;" & _
' "data source=" & strservername & ";" & _
' "initial catalog=" & strdbname & ";" & _
' "user id=" & struid & ";" & _
' "password=" & strpwd & ";"
'
'用它,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) " & _
' " 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 & i, varitem)
strtext = vba.replace(strtext, strcharpre & "/", strcharpre)
next
gcombinationstring = strtext
end function
新聞熱點
疑難解答