请有ASP中使用数组的例子?

sunminjin 2007-05-29 05:45:32
如上,谢谢!
...全文
218 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wantop 2007-05-31
  • 打赏
  • 举报
回复
学习!!
chouchy 2007-05-31
  • 打赏
  • 举报
回复
<%
dim A(5),B(),C '声明一个具有6个元素的数组A,和一个动态数组B,以及一个变量C
'初始化A数组
for i=0 to ubound(A)
A(i)=i
next
'循环输出A数组元素
for i=0 to ubound(A)
response.write "A(" & i & ")=" & A(i) & "<br>"
next

'输出一个分割线
response.write "<hr>"

'重新定义B数组
redim B(10)
'初始化B数组
for i=0 to ubound(B)
B(i)=i
next
'输出B数组元素
for i=0 to ubound(B)
response.write "B(" & i & ")=" & B(i) & "<br>"
next

'输出一个分割线
response.write "<hr>"

'初始化C,使之为一数组
C=Array(1,2,3)
'输出C数组元素
for i=0 to ubound(C)
response.write "C(" & i & ")=" & C(i) & "<br>"
next

%>
nanyang9 2007-05-29
  • 打赏
  • 举报
回复
这里是根据数组中的数据来初始化数据库的一个纯VBScript脚本。里面除了显示消息与ASP不同外,其途的与ASP中的语法及接口是完全一样的。
-------------------------------------------------------------------------------
' VB Script Document
Dim NyDb,NyDbPath
NyDb = "#nywow.mdb"
NyDbPath = CreateObject("Scripting.FileSystemObject").GetFolder(".").Path&"\"&NyDb
Set Con = WScript.CreateObject("ADODB.Connection")
On Error Resume Next
Con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & NyDbPath
If Err.Number <> 0 Then
WScript.Echo "Database Link is wrong, check link string."
WScript.Quit
End If
On Error GoTo 0
WScript.Echo "Data initialization start ."

Dim times(12,5)
times(1,1)=0
times(2,1)=0
times(3,1)=0
times(4,1)=0
times(5,1)=0
times(6,1)=0
times(7,1)=0
times(8,1)=0
times(9,1)=0
times(10,1)=0
times(11,1)=0
times(12,1)=0

times(1,2)=12
times(2,2)=24
times(3,2)=24
times(4,2)=24
times(5,2)=24
times(6,2)=12
times(7,2)=24
times(8,2)=24
times(9,2)=24
times(10,2)=24
times(11,2)=24
times(12,2)=24

times(1,3)=24
times(2,3)=48
times(3,3)=48
times(4,3)=48
times(5,3)=48
times(6,3)=48
times(7,3)=48
times(8,3)=48
times(9,3)=48
times(10,3)=48
times(11,3)=48
times(12,3)=48

times(1,4)=48
times(2,4)=72
times(3,4)=72
times(4,4)=96
times(5,4)=96
times(6,4)=72
times(7,4)=72
times(8,4)=72
times(9,4)=72
times(10,4)=72
times(11,4)=72
times(12,4)=72

times(1,5)=84
times(2,5)=120
times(3,5)=120
times(4,5)=144
times(5,5)=144
times(6,5)=144
times(7,5)=120
times(8,5)=120
times(9,5)=120
times(10,5)=120
times(11,5)=120
times(12,5)=120

Dim nn,hh,dd,pp,i,j,k
nn=0
For k=1 To 12
For i=1 To 5
For j=i+1 To 5
hh=SumTime(i,j,k)
pp=SumPrice(hh)
dd=GetDays(hh)
sql="INSERT INTO reputation(r_name,r_start,r_end,[price],[days],[hours]) VALUES("&k&","&i&","&j&","&pp&","&dd&","&hh&")"
'WScript.Echo sql
'WScript.Quit
Con.Execute sql
nn=nn+1
Next
Next
Next
Con.Close
Set Con=Nothing
WScript.Echo "Level Data initialization finished. Add a total of "&nn&" data."

'根据数组计算所花小时数
Function SumTime(s_level,e_level,kk)
Dim ii
SumTime=0
For ii=s_level+1 To e_level
SumTime=SumTime+times(kk,ii)
Next
End Function

'根据小时间数计算所需金额 
Function SumPrice(H)
Dim P
If H<=12 Then
P=1.0
ELseIf H>12 And H<24 Then
P=0.8
ElseIf H>=24 And H<72 Then
P=0.7
ElseIf H>=72 And H<120 Then
P=0.65
ElseIf H>=120 And H<192 Then
P=0.6
ElseIf H>=192 And H<240 Then
P=0.55
ElseIf H>=240 And H<288 Then
P=0.5
ElseIf H>=288 And H<=360 Then
P=0.45
Else P=0.42
End If
SumPrice=P*H
End Function

'把小时数换算成天数,精确到0.5,向后取整
Function GetDays(H)
Dim d0,d1
d0=Int(100*H/24)
d1=d0 Mod 100
If d1>0 And d1<50 Then
d1=50
ElseIf d1>50 Then
d1=100
End If
GetDays=(d0-(d0 Mod 100)+d1)/100
End Function
-------------------------------------------------------------------------------

28,390

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧