快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

用函数简化你的字符串连接语句

\\\'你是否异常讨厌 用 & 一大串的连接变量?
\\\'你是否不得不常常使用""与"""" ?
\\\'就似乎这样:
\\\'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
返回类别: 教程
上一教程: ACTIVEX深入浅出(二)
下一教程: 挂QQ的网页源代码[ASP/PHP/JS]

您可以阅读与"用函数简化你的字符串连接语句"相关的教程:
· 一个检测一个字符串在另一个字符串当中出现几次的函数
· ASP中字符串函数的应用
· ADO连接数据库字符串大全
· 使用SPLIT分割多字符的字符串的方式
· 一套加解密字符串的函数
    微笑服务 优质保证 索取样品