想试着做一个简单的读取RSS新闻的页面
根据VBscript的数据类型定义,结合利用VarType函数,构造以下自动处理函数InitdataType,
输入两个参数,要处理数据本身(theDate)和准备输出的数据类型(theReturnType,整数型): theReturnType强制返回的数据类型 ,同VarType返回值定义的意义一样, ‘’theReturnType 如果忽略: 返回同theDate一样的数据类型.
比较常见的NULL返回,对于字符串型返回空字符串,对各种于数值返回0值,对于逻辑值返回FALSE(假),对于日期
返回最早的日期
函数程序:
Function InitdataType(theDate,theReturnType)
‘’返回或强制指示变量子类型的值。theDate 参数可以是任何变量。
‘’theReturnType(整数型): 强制返回的数据类型 ,同VarType返回值定义的意义一样
‘’theReturnType 如果忽略: 返回同theDate一样的数据类型.
‘’下面引用的函数VarType(varname)会返回指示变量子类型的值。,varname 参数可以是任何变量。
‘’VarType函数返回值的意义如下:
‘’vbEmpty 0 Empty(未初始化)
‘’vbNull 1 Null(无有效数据)
‘’vbInteger 2 整数
‘’vbLong 3 长整数
‘’vbSingle 4 单精度浮点数
‘’vbDouble 5 双精度浮点数
‘’vbCurrency 6 货币
‘’vbDate 7 日期
‘’vbString 8 字符串
‘’vbObject 9 Automation 对象
‘’vbError 10 错误
‘’vbBoolean 11 Boolean
‘’vbVariant 12 Variant(只和变量数组一起使用)
‘’vbDataObject 13 数据访问对象
‘’vb???? 14 小数
‘’vbByte 17 字节
‘’vbArray 8192 数组
On Error Resume Next
‘’Err.Clear
dim n_dataType,vo_ReData,vo_renewdata,c_TypeName
n_dataType = VarType(theDate)
‘’c_TypeName = TypeName(theDate)
If n_dataType<2 then
if isNumeric(theReturnType) then
Select Case theReturnType
case 1
vo_renewdata=NULL
case 2
vo_renewdata=0
case 3
vo_renewdata=0
case 4
vo_renewdata=0
case 5
vo_renewdata=0
case 6
vo_renewdata=0
case 7
vo_renewdata=0
case 8
vo_renewdata=""
case 11
vo_renewdata=DEF_False
case 14
vo_renewdata=0
case 17
vo_renewdata=chr(0)
case else
vo_renewdata=theDate
end Select
else
vo_renewdata=theDate
end if
else
if isNumeric(theReturnType) then
Select Case theReturnType
case 0
vo_renewdata=Empty
case 1
vo_renewdata=NULL
case 2
if isNumeric(theDate) then
vo_renewdata=cInt(theDate)
else
vo_renewdata=Eval("0+" & theDate &"")
if not isNumeric(vo_renewdata) then vo_renewdata=0
end if
case 3
if isNumeric(theDate) then
vo_renewdata=cLng(theDate)
else
vo_renewdata=Eval("0+" & theDate &"")
if not isNumeric(vo_renewdata) then vo_renewdata=0
end if
case 4
if isNumeric(theDate) then
vo_renewdata=cSng(theDate)
else
vo_renewdata=Eval("0+" & theDate &"")
if not isNumeric(vo_renewdata) then vo_renewdata=0
end if
case 5
if isNumeric(theDate) then
vo_renewdata=cDbl(theDate)
else
vo_renewdata=Eval("0+" & theDate &"")
if not isNumeric(vo_renewdata) then vo_renewdata=0
end if
case 6
if isNumeric(theDate) then
vo_renewdata=cCur(theDate)
else
vo_renewdata=0
end if
case 7
if isDate(theDate) then
vo_renewdata=theDate
else
vo_renewdata=cDate(0)
end if
case 8
if Not isNull(theDate) then
vo_renewdata=cStr(theDate)
else
vo_renewdata=""
end if
case 11
If (not isNull(theDate)) or theDate<>"" Then
vo_renewdata=DEF_True
else
vo_renewdata=DEF_False
end if
case 14
if isNumeric(theDate) then
vo_renewdata=cDbl(theDate)
else
vo_renewdata=Eval("0+" & theDate &"")
if not isNumeric(vo_renewdata) then vo_renewdata=0
end if
case 17
if Not isNull(theDate) then
vo_renewdata=CByte(theDate)
else
vo_renewdata=CByte(0)
end if
case else
vo_renewdata=theDate
end Select
else
vo_renewdata=theDate
end if
end if
err.clear
‘’vMsgBox("rtn:" & cstr(vo_renewdata) & " type:" & cstr(c_TypeName)) & "/" & cstr(n_dataType)
InitdataType=vo_renewdata
End Function
在实际程序中调用示意:
Set conn = Server.CreateObject("ADODB.Connection")
conn.open xDb_Conn_Str
Set rs=Server.Createobject("ADODB.Recordset")
dim n_OD,cNewName ,nNewValue
n_OD=1.2
sql = "SELECT sl_Name,sl_Value FROM Table_SL WHERE sl_name=‘’mike‘’"
rs.open sql,conn,1
if not rs.eof then
cNewName = InitdataType(rs("sl_Name"),8)
nNewValue = InitdataType(rs("sl_Value"),5) * n_OD
response.write cNewName & "的标准零售价为:" & nNewValue & "(元)"
end if
rs.Close
Set rs=Nothing
- · ASP翻页的实现方法
- · 用ASP建立网站地图
- · 获得ASP的中文日期字符串
- · 利用索引服务和ASP建立面向整个网站搜索程序
- · ASP+中不再依赖Cookie的设定方法
- · 负载平衡环境下的SESSION管理
- · ASP应用中数据库记录的选取与过滤
- · ASP的多条件动态查询
- · 优化ASP应用程序技巧四则
- · ASP中ActiveX控件的内嵌及调用
- · 在win2003上用cdo代替CDONTS发邮件
- · Freetextbox的使用
- · asp提供在线文章翻译的功能
- · 关于Request
- · 基于B/S下的IC智能卡的安全问题
- · ASP小偷偷取地址并生成html
- · 求助关于远程访问ACCESS数据库的问题
- · Forms验证中的roles
- · 一个比较精辟的索引文章
- · T-SQL: 17 个与日期时间相关的自定义函数(UDF)
- · 限制某段IP地址
- · 调用winrar压缩文件夹
- · ASP做的剪包锤游戏
- · 如何在ASP+中使用自定义的PAGELET
- · 利用ASP编写动态回复表单
- · 用ASP和javascript实现网页上的动态分级目录
- · 在Windows 2000中配置ASP开发环境
- · ASP数据库编程SQL常用技巧
- · 用ASP方式实现拥有动态伸缩层次列表的主页
- · ASP写入响应流的最高效率测试结果
- · ASP网页访问权的控制
- · 用ASP实现的2000年倒记时程序
- · 用ASP实现网上考试系统
- · 用ASP构筑主页聊天室
- · ASP万用分页程序
- · 用ASP制作张扬个性的调查系统
- · 用ASP建立一个简单的聊天室
- · 用ASP设计网站在线人数统计程序
