有關vb既程式~唔識解~

2008-12-08 7:46 am
For q = 0 To 50
a1 = Int(Rnd() * 14)
a2 = Int(Rnd() * 14)
Dim temp As Integer
temp = x(a1)
x(a1) = x(a2)
x(a2) = temp
Next
y(0) = x(0) + x(1)
y(1) = x(2) + x(3)
y(2) = x(4) + x(5)
y(3) = x(6) + x(7)
y(4) = x(8) + x(9)
lstquestion.Items.Add(" ? + " & x(0) & " = " & y(0))
lstquestion.Items.Add(" ? + " & x(2) & " = " & y(1))
lstquestion.Items.Add(" ? + " & x(4) & " = " & y(2))
lstquestion.Items.Add(" ? + " & x(6) & " = " & y(3))
lstquestion.Items.Add(" ? + " & x(8) & " = " & y(4))
lstquestion.SelectedItem = (" ? + " & x(0) & " = " & y(0))
txtanswer.Focus()
-------------------------------------------------------------------------------

回答 (1)

2008-12-08 9:31 pm
✔ 最佳答案
雖然program個intention好明顯,要100% sure你隻program係點行,首先要知道究竟array x係用黎做乜
呢個program驟眼睇似係比小學生玩果D加數練習,暫且假定x係一堆數字先

逐part拆啦
首先0至50果個for loop(ln.1-8)做ge野主要就係抽兩個數(0-13)作為index,然後將x(a1)同x(a2)調轉
例如抽到a1=2, a2=4,就將x(2)同x(4)的value調轉。
經過50次咁樣ge過程,希望將x(0)至x(13)的value調到立立亂

跟著ln9-13就係應該係set五條題目,以array "y"儲存答案。y(i)的數值就是x(i)+x(i+1)。因為array x o係上面已經撈亂晒,所以就可以做到一個psuedo-randomly出題目的效果。

最後ln.14-19就係將D set好晒ge題目放入去個list入面,將第一題set做list的default value

假設x(0)=3, x(1)=4,題目的格式就係:

? + 3 = 7

txtanswer就應該係比學生答問題的textbox,學生就係要答"?"所表示的數字。以上面果個example,就係4。

其實個program都好奇怪,點解唔直接assign一個random value入x而要大費周章先assign一堆數再撈亂50次,識用forloop又唔用forloop處理埋入問題的過程。不過睇隻program應該都係新手寫,不怪不怪......
參考: 大學電腦系的學生,精補電腦XD


收錄日期: 2021-04-13 16:17:44
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20081207000051KK02384

檢視 Wayback Machine 備份