0
對不起,但你能幫我解決我的問題嗎?Visual Basic的測驗程序
我是新的視覺基本編程和一切都很好,直到我們的主題轉移到數組。我試圖瞭解它是使用Java的代碼。 (例如:方法被稱爲功能..)
我的教授給了我們一個練習來創建一個測驗程序,詢問用戶超過5個問題(在文本框中)的選擇(按鈕),並計算得分最後(都只是一種形式)。如果用戶點擊一個按鈕,它會告訴它是對還是錯,然後繼續改變問題以及選擇。
*必填項: - 用戶完成測驗後,得分將會顯示出來,並且應該有一個重新啓動按鈕,並且所有的問題都會被隨機再次詢問沒有模式。 - 嘗試製作功能。
我試着從昨天開始在網上搜索,我的代碼仍然沒有進展。
Public Class Form1
Dim questions(5) As String
Dim answers(5) As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Method/Function for loading the Q&A
loadQsAndAs()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.Close()
End Sub
Private Sub loadQsAndAs()
'Questions
questions(0) = "What is 1 + 1?"
questions(1) = "Who is the first man to walk on the Moon?"
questions(2) = "What is the name of the main character in the movie: Yes Man!(2007)"
questions(3) = "If I gave you three apples and you ate two, how many is left?"
questions(4) = "What do you want in your final grade?"
questions(5) = "What is the name of the thing(s) that you use whenever you eat?"
'Answers
answers(0) = "2"
answers(1) = "Neil Armstrong"
answers(2) = "Jim Carrey"
answers(3) = "1"
answers(4) = "A 4.0"
answers(5) = "A Spoon and Fork"
TextBox1.Text = setTheQuestion()
Button1.Text = setTheAnswer1()
Button2.Text = setTheAnswer2()
Button3.Text = setTheAnswer3()
Button4.Text = setTheAnswer4()
End Sub
Private Function setTheQuestion() As String
Dim randomValue As New Random
Dim randomQ As String = ""
Dim i As Integer
Dim index As Integer
For i = 0 To 0
index = randomValue.Next(0, questions.Length)
randomQ &= questions(index)
Next
Return randomQ
End Function
Private Function setTheAnswer1() As String
Dim randomValue As New Random
Dim randomAns As String = ""
Dim i As Integer
Dim index As Integer
For i = 0 To 0
index = randomValue.Next(0, answers.Length)
randomAns &= answers(index)
Next
Return randomAns
End Function
Private Function setTheAnswer2() As String
Dim randomValue As New Random
Dim randomAns As String = ""
Dim i As Integer
Dim index As Integer
For i = 0 To 0
index = randomValue.Next(1, answers.Length)
randomAns &= answers(index)
Next
Return randomAns
End Function
Private Function setTheAnswer3() As String
Dim randomValue As New Random
Dim randomAns As String = ""
Dim i As Integer
Dim index As Integer
For i = 0 To 0
index = randomValue.Next(2, answers.Length)
randomAns &= answers(index)
Next
Return randomAns
End Function
Private Function setTheAnswer4() As String
Dim randomValue As New Random
Dim randomAns As String = ""
Dim i As Integer
Dim index As Integer
For i = 0 To 0
index = randomValue.Next(3, answers.Length)
randomAns &= answers(index)
Next
Return randomAns
End Function
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
loadQsAndAs()
End Sub
End Class
我的問題是:
我如何在數組中的問題和我的選擇,隨機出現,每當用戶啓動或重啓程序?
我該如何編碼,隨機問題也會有其他3個隨機答案的正確答案? (因爲我只是隨機化的答案,它不斷重複一些選擇)
任何人都可以幫助我嗎?
因此,做一個隨機整數,然後連接該整數到我的問題和答案?像一個使序列隨機的值? – Coolai 2012-08-07 08:21:22
當測驗開始時,隨機創建一個如4,3,1,2,5,0的序列 - 例如使用List。這表示您的問題顯示順序。然後顯示問題4首先,然後顯示3,等等。 – podiluska 2012-08-07 08:25:39
「使用列表,例如」您的意思是列表(T)類? – Coolai 2012-08-07 10:48:39