VB 整問答程式

2007-11-01 11:15 pm
想用VB寫一個問問題既
問題要有10條 要5重複 但要隨機
要有4個答案選 得1個係對既
答完10條之後要彈個野出黎講答對左幾題
唔該a 好急用a  要詳細d  幫幫忙

回答 (2)

2007-11-03 3:15 pm
✔ 最佳答案
1. 定義 global variables, 問題和答案可放進 text file load 出來, 如果嫌麻煩可直接放係 variable 內:
dim n as integer ' number of questions
dim questions(1 to 10) as string
dim answers(1 to 10, 1 to 4) as string
dim correctAns (1 to 10) as integer
dim seq(1 to 10) as integer
dim questionIndex
dim questionNumber
dim numberOfCorrect
n = 10
questions(1) = "blah blah blah...?"
answers(1,1) = "answer a"
answers(1,2) = "answer b"
answers(1,3) = "answer c"
answers(1,4) = "answer d"
correctAns(1) = 3
questions(2) = "dah dah dah...?"
answers(2,1) = "answer 1"
answers(2,2) = "answer 2"
answers(2,3) = "answer 3"
answers(2,4) = "answer 4"
correctAns(2) = 2
...................... 如此類推


2. 將問題編號放進一個 array 內, 如 1 到 10:
for i = 1 to n
seq[i] = i
next i

3. 將 array 內之問題編號隨機排放:
for i = n to 1 step -1
idx = Int(RND() * (i + 1))
tmp = seq(i)
seq(i) = seq(idx)
seq(idx) = tmp
next i

4. 遊戲開始:
questionIndex = 1
numberOfCorrect = 0


5. 每次出問題時
questionNumber = seq(questionIndex)
questionIndex = questionIndex + 1

6. 顯示第 questionNumber 條問題, 供玩家作答, 如:
labelQuestion.caption = questions(questionNumber)
labelAnswer1.caption = answers(questionNumber, 1)
labelAnswer2.caption = answers(questionNumber, 2)
labelAnswer3.caption = answers(questionNumber, 3)
labelAnswer4.caption = answers(questionNumber, 4)

7. Check 答案, 如:
if playerChoice = correctAns(questionNumber) then numberOfCorrect = numberOfCorrect + 1

8. 當 questionIndex > n 時, 所有問題問完, 顯示答對左幾題 (numberOfCorrect).
2007-11-02 8:59 am
你先要dim d變數save d 問題和答案 or save在 text box 到
用 option button 比人選答案


for a=1 to 10
問問題
if 對 then
r=r+1
end if
end
Print "答對:" + r


收錄日期: 2021-04-13 21:01:55
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20071101000051KK01480

檢視 Wayback Machine 備份