<%
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
这里是根据数组中的数据来初始化数据库的一个纯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 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
-------------------------------------------------------------------------------