我想检查数据是否以"01"
开头(意味着它是电话号码),我想在电话号码前加"60"
并将字符串内的短划线替换为空。
我在此行if Field Like "01*" Then
Microsoft VBScript运行时错误'800a0023'
Sub或Function not defined
希望有人能够告诉我出了什么问题。
<%Option Explicit%>
<%
Dim strConn, strScriptName,strSQL
strConn = Application("eDSNSMS")
strSQL = Request.querystring("SQL")
sub Write_CSV_From_Recordset(RS)
if RS.EOF then
exit sub
end if
dim RX
set RX = new RegExp
RX.Pattern = "\r|\n|,|"""
dim i
dim Field
dim Separator
do until RS.EOF
Separator = ""
for i = 0 to RS.Fields.Count - 1
Field = RS.Fields(i).Value & ""
if RX.Test(Field) then
Field = """" & Replace(Field, """", """""") & """"
end if
if Field Like "01*" Then
Field = "60" + Field
Field = """" & Replace(Field, "-", "") & """"
end if
Response.Write Separator & Field
Separator = ","
next
Response.Write vbNewLine
RS.MoveNext
loop
end sub
Dim objRS, objConn
set objConn = server.CreateObject("ADODB.Connection")
objConn.ConnectionString = strConn
objConn.Open
set objRS = server.CreateObject("ADODB.RecordSet")
objRS.Open strSQL, strConn, 0, 1
Write_CSV_From_Recordset objRS
Response.ContentType = "text/csv"
Response.AddHeader "Content-Disposition", "attachment;filename=export.csv"
%>
答案 0 :(得分:2)
VBScript没有在VBA和VB6中找到Like
运算符。你必须使用其他方法测试你的字符串。
例如,您可以更改:
if Field Like "01*" Then
要:
If Left(Field, 2) = "01" Then
此外,您应该使用&
来连接字符串,尤其是在处理可以被视为数字的值时,就像您在这里一样:
Field = "60" + Field
否则,您将面临汇总而非连接的风险。