| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 556 人关注过本帖
标题:随即产生考试试题,这段循环代码看不懂,
只看楼主 加入收藏
Kettyjin1983
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2007-8-17
结帖率:66.67%
收藏
 问题点数:0 回复次数:6 
随即产生考试试题,这段循环代码看不懂,

这段代码是这样的:红色的那一部分真是不懂啊。

Dim num(),k,i,x,j,ans()
redim num (totalq)
redim ans (totalq)

k = 1
Randomize

For i = 1 To totalq
x = Round(Rnd * totalrec)
'give record count
For j = 1 To k
If num(j) = x Then
i = i - 1
Exit For
End If
Next
If j > k Then
num(k) = x
k = k + 1
End If
Next

搜索更多相关主题的帖子: 试题 考试 代码 
2007-11-14 14:53
xiuit
Rank: 1
等 级:新手上路
帖 子:22
专家分:0
注 册:2007-11-12
收藏
得分:0 
NUM的值是什么呀,totalrec是从哪儿来的呀

思想重于代码
2007-11-14 22:29
Kettyjin1983
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2007-8-17
收藏
得分:0 

<%@ Language=VBScript %>
<%option explicit
%><!-- #INCLUDE FILE = "connect_ama.asp" --><%

dim myrs
set myrs = server.createobject("ADODB.recordset")
myrs.open "select * from all_exams where ExamName ='" & Request.Form ("start") & "'" ,myconn

''''''''''''''''''''''''''''''''''''''''''''''''''
dim q_id1, q_id2, code, totaltime, ppercent, totalq, expire, examname
q_id1 = myrs("sq_id")
q_id2 = myrs("eq_id")
totaltime = myrs("totalTime")
totalq = myrs("totalQuestions")
examname = myrs("ExamName")
ppercent = myrs("ppercentage")
code = myrs("code")
expire = myrs("expireDate")
myrs.Close
session("totalquestions")=totalq
''''''''''''''''''''''''''''''
myrs.open "select * from q_bank where q_id between " & q_id1 & " and " & q_id2 ,myconn,3
'3=adOpenStatic,then only myrs.recordcount will work
''''''''''''''''''''''''''''''
dim totalrec
totalrec = myrs.RecordCount
session.Contents("ExamName")=Request.Form ("start")
'Response.Cookies("totaltime")= cstr(totaltime)


'if myrs.Fields("ExpireDate") < Date then
'Response.Write "<h5>EXPIRED ''''''''<H5>"
'end if


' Response.Write "total time=" & totaltime & "<hr> total q=" & totalq & "<hr> total rec=" & totalrec &"<hr>"
Dim num(),k,i,x,j,ans()
redim num (totalq)
redim ans (totalq)

k = 1
Randomize

For i = 1 To totalq
x = Round(Rnd * totalrec)
'give record count
For j = 1 To k
If num(j) = x Then
i = i - 1
Exit For
End If
Next
If j > k Then
num(k) = x
k = k + 1
End If
Next
'''''''''''''''''''''''''''''''''''
for i=1 to totalq
ans(i)="Not Attempted"
'Response.Write i & " | " &num(i)& " | "
myrs.MoveFirst
myrs.Move num(i)-1
num(i)=myrs("q_id")
'Response.Write num(i) & " |<br> "
Next
Session("Questions")=num
Session("Answers")=ans
Session("Counter")=1
Session("examover")=0
Session ("examname")= examname
Session("ppercentage")= ppercent

'''''''''''''''''''''''''''''''''
'closing order important'''''''''
myrs.close
myconn.close
set myconn=nothing
set myrs=nothing
'''''''''''''''''''''''''''''''''

'Response.Redirect "exam_paper.asp"
Response.Cookies(examname & "totaltime")= cstr(totaltime)

%>

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
</HEAD>
<BODY>
<form name=examform action="exam_paper.asp" method=post>
<input type=hidden name=qno value=1>
<input type=hidden name=totalq value=<%=totalq%>>
</form>
<script language="JavaScript">
document.examform.submit()
</script>


</BODY>
</HTML>

2007-11-15 10:31
Kettyjin1983
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2007-8-17
收藏
得分:0 

我把整段代码都贴上了,就是下面这段循环看不懂,帮帮我吧。
For i = 1 To totalq
x = Round(Rnd * totalrec)
'give record count
For j = 1 To k
If num(j) = x Then
i = i - 1
Exit For
End If
Next
If j > k Then
num(k) = x
k = k + 1
End If
Next

2007-11-15 10:34
multiple1902
Rank: 8Rank: 8
等 级:贵宾
威 望:42
帖 子:4881
专家分:671
注 册:2007-2-9
收藏
得分:0 

Dim num(),k,i,x,j,ans()
redim num (totalq)
redim ans (totalq)

k = 1
Randomize

For i = 1 To totalq
x = Round(Rnd * totalrec)
'give record count
For j = 1 To k
If num(j) = x Then ' num里的元素还没赋值吧,怎么能引用呢?
i = i - 1
Exit For
End If
Next
If j > k Then
num(k) = x
k = k + 1
End If
Next

2007-11-15 11:14
Kettyjin1983
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2007-8-17
收藏
得分:0 
晕,也就是这段代码本身就有问题了。那怎么办啊,怎么改啊?
2007-11-15 11:45
Kettyjin1983
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2007-8-17
收藏
得分:0 

运行是成功得,这是怎么回事啊?哪位大人帮我看看啊

2007-11-15 13:10
快速回复:随即产生考试试题,这段循环代码看不懂,
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032028 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved