对象 例3-4 <HTML> <HEAD>< TITLE> Select Case语句</TTE> <SCRIPT LANGUAGE="VBScript"> Sub but tonl Onclick( grade=trim( InputBox("请输入等级:(优、良、中、可、差)","学生等级","中")) Select Case grade Case"差" score="成绩低于60分,不及格! Case"可" score="成绩在60到70分之间,及格! Case"中" score="成绩在70到80分之间,中!" Case"良" score="成绩在80到90分之间,良好!" 绩在90到100分 分之间,优 Case else score="输入的等级应该为(优、良、中、可、差)! End select MsgBox score End sub <BODY> <INPUT type="button"name="button1"value="5"> </BODY> 程序的执行结果与例3-4-1相同 例3-4-3 <HEAD> <T工TLE>流程控制语句的使用</T工TLE> Sub but tonl OnClick Document. write(<Pre> D。 cument. Write("*") Document. Write(Space(5)&i Document. Writeln Document. Write(3& If Len( temp)=1 Then
第 4 章 Response 与 Request 对象 11 例 3-4-2: <HTML> <HEAD><TITLE>Select Case 语句</TITLE> <SCRIPT LANGUAGE="VBScript"> Sub button1_OnClick() Dim score grade=trim(InputBox("请输入等级:(优、良、中、可、差)","学生等级","中")) Select Case grade Case "差" score="成绩低于 60 分,不及格!" Case "可" score="成绩在 60 到 70 分之间,及格!" Case "中" score="成绩在 70 到 80 分之间,中!" Case "良" score="成绩在 80 到 90 分之间,良好!" Case "优" score="成绩在 90 到 100 分之间,优秀!" Case Else score="输入的等级应该为(优、良、中、可、差)!" End Select MsgBox score End Sub </SCRIPT></HEAD> <BODY> <INPUT type="button" name="button1" value="查看"> </BODY> </HTML> 程序的执行结果与例 3-4-1 相同。 例 3-4-3: <HTML> <HEAD> <TITLE>流程控制语句的使用</TITLE> </HEAD> <Script Language="VBScript"> <!-- Sub button1_OnClick Document.Write("<Pre>") Document.Write("*") i=1 While i<10 Document.Write(Space(5)&i) i=i+1 Wend Document.WriteLn For j=1 To 9 Document.Write(j&" ") For k=1 To j temp=j*k If Len(temp)=1 Then
ASP程序设计教程 Document. Write(Space(4)temp&"") Document. Write(Space(3)&t Document. Writeln Document. Write(</Pre>") Document. Write(*) End sub </script> <BODY> <INPUT type="button"name="button1"value="ffsa"> 例3-5-1 < TITLE>函数的定义和使用</ TITLE> </HEAD> <Script Language="VBScript 产生固定范围并且没有重复的随机数 Function rndnum(a, k, w) randomiz t(fix(rnd*k)) if cint (a(m))=cint(num) then . ze num=cint(fix(rnd*k)) end if LIn
12 ASP 程序设计教程 Document.Write(Space(4)&temp&" ") Else Document.Write(Space(3)&temp&" ") End If Next Document.WriteLn Next Document.Write("</Pre>") i=1 Do While i<60 Document.Write("*") i=i+1 loop End Sub --> </Script> <BODY> <INPUT type="button" name="button1" value="开始"> </BODY> </HTML> 例 3-5-1: <HTML> <HEAD> <TITLE>函数的定义和使用</TITLE> </HEAD> <Script Language="VBScript"> <!-- '产生固定范围并且没有重复的随机数 Function rndnum(a,k,w) randomize num=cint(fix(rnd*k)) m=0 while m<=w-1 if cint(a(m))=cint(num) then randomize num=cint(fix(rnd*k)) m=0 else m=m+1 end if wend rndnum=num End Function Sub button1_OnClick Dim arr(10)
对象 arr (i)=n Next End sub </Script> INPUt type="button"name="button1" value="ffa" </BODY> </HTML> 例3-5-2 <HEAD> <TITE>过程的定义和使用</ TITLE> Sub but tonl OnClick MsgBOx("请等待2秒钟,马上开始!") MsgBOx("窗前明月光,疑是地上霜。") MsgBOx("举头望明月,低头思故乡 End sub Sub DelayTime(Delay) Seconds inday=24*60*60 EndTime=Timer+Delay If EndT ime>Secondsinday Then Do While Timer>Endtime Do While Timer<endtime End sub <BODY> </BODY> </HTML>
第 4 章 Response 与 Request 对象 13 For i=0 to 9 n=rndnum(arr,100,i) arr(i)=n Document.Write(n&" ") Next End Sub --> </Script> <BODY> <INPUT type="button" name="button1" value="开始"> </BODY> </HTML> 例 3-5-2: <HTML> <HEAD> <TITLE>过程的定义和使用</TITLE> </HEAD> <Script Language="VBScript"> <!-- Sub button1_OnClick MsgBox("请等待 2 秒钟,马上开始!") Call DelayTime(2) MsgBox("窗前明月光,疑是地上霜。") DelayTime(3) MsgBox("举头望明月,低头思故乡。") End Sub Sub DelayTime(Delay) Secondsinday=24*60*60 EndTime=Timer+Delay If EndTime>Secondsinday Then EndTime=EndTime-Secondsinday Do While Timer>EndTime Loop End If Do While Timer<EndTime Loop End Sub --> </Script> <BODY> <INPUT type="button" name="button1" value="开始"> </BODY> </HTML>
ASP程序设计教程 例3-7-1 < TITLE> Window对象的使用</T工TE> </HEAD> <Script Language="VBScript"> Sub but tonl onc Window. Alert not Sub but ton2 OnClick Window,open"1ogin.htm","新窗口","too1bar=no"," sizeable=no", width=200, height=200 Window. status="窗口已经打开!〃 <BODY OnLoad=openwin()'> INPUT type=" button"name=" button1"va1ue="显示时间"><p> <INPUT type=button"name="button2"value="xFi"><p> 例3-7-2 < TITLE>按顺序输入注册信息</ TITLE> <Script id=client Event HandlersvBS Language=VBScript"> Sub windows onload Form1. xm. Focus End sub Sub xm onkeypress vent. Keycode=13 then Form1. mm. Focus End sub Sub mm onkeypress Forml. qrmm Focus End if
14 ASP 程序设计教程 例 3-7-1: <HTML> <HEAD> <TITLE>Window 对象的使用</TITLE> </HEAD> <Script Language="VBScript"> <!-- Sub button1_OnClick Window.Alert now() End Sub Sub button2_OnClick Window.close End Sub Sub openwin() Window.open "login.htm","新窗口","toolbar=no","rsizeable=no", width=200,height=200 Window.status=”窗口已经打开!” End Sub --> </Script> <BODY OnLoad='openwin()'> <INPUT type="button" name="button1" value="显示时间"><p> <INPUT type="button" name="button2" value="关闭"><p> </BODY> </HTML> 例 3-7-2: <HTML> <HEAD> <TITLE>按顺序输入注册信息</TITLE> <Script id=clientEventHandlersVBS Language="VBScript"> <!-- Sub Windows_onload Form1.xm.Focus End Sub Sub xm_onkeypress If Window.Event.KeyCode=13 then Form1.mm.Focus End If End Sub Sub mm_onkeypress If Window.Event.KeyCode=13 then Form1.qrmm.Focus End If
与 Request对象 End sub Sub qrmm onkeypress If Window Event. KeyCode=l3 then Forml. nl. Focus End if End sub Sub nl onkeypress If Window Event. KeyCode=13 then Forml dh. Focus End if End sub Sub ch onkeypress If Window Event. KeyCode=13 then Form1.zz. Focus End if End sub Sub zz onkeypress If Window Event. KeyCode=13 then Forml email End if End sub Sub email on keypress If Window Event. KeyCode=13 then Form1. Button1. Focus End if End sub Sub but ton1 Onclick Dim txt l, txt2, txt3, txt4, txt5, txt6, txt, alltxt txt1=Form1. xm value txt2=Form1. nl value xt3=Forml dh value txt4=Form1.zz. value txt5=Form1. mm. value txt6=Forml grmm value txt=Forml email value If txt=" then MsgBOx"姓名不能为空!" Forml.xm. Focus Exit Sub End if If txt5= then MsgBOx"密码不能为空!" Forml. mm. Focus cit Sub End工f If Len(txt5)<6 or Len(txt5)>12 Then
第 4 章 Response 与 Request 对象 15 End Sub Sub qrmm_onkeypress If Window.Event.KeyCode=13 then Form1.nl.Focus End If End Sub Sub nl_onkeypress If Window.Event.KeyCode=13 then Form1.dh.Focus End If End Sub Sub dh_onkeypress If Window.Event.KeyCode=13 then Form1.zz.Focus End If End Sub Sub zz_onkeypress If Window.Event.KeyCode=13 then Form1.email.Focus End If End Sub Sub email_onkeypress If Window.Event.KeyCode=13 then Form1.Button1.Focus End If End Sub Sub button1_OnClick Dim txt1,txt2,txt3,txt4,txt5,txt6,txt7,alltxt txt1=Form1.xm.value txt2=Form1.nl.value txt3=Form1.dh.value txt4=Form1.zz.value txt5=Form1.mm.value txt6=Form1.qrmm.value txt7=Form1.email.value If txt1="" then MsgBox "姓名不能为空!" Form1.xm.Focus Exit Sub End If If txt5="" then MsgBox "密码不能为空!" Form1.mm.Focus Exit Sub End If If Len(txt5)<6 or Len(txt5)>12 Then