• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

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

发布: 2007-7-02 11:08 | 作者: admin | 来源: | 查看: 8次 | 进入软件测试论坛讨论

领测软件测试网

@#2004/07/27 朱彦志(goodidea)

@#你是否非常讨厌 用 & 一大串的连接变量?
@#你是否不得不经常使用""与"""" ?
@#就好像这样:
@#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


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网