i would like ask you how i can generate a multilple choice questions chosen randomly from a list of questions with anwers using functions in visual basic 6.0?


how about you store them on the database? (of course, it sould be.) then each questions will have their own ID's. since they have their own IDs you can use

Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
'where upperbound is the largest number range
'lowerbound is the lowest number range
'Rnd is a VB built in function, and so as Int

to generate random numbers which will be the questions ID numbers. This is only my point of view.

hi there,

you should do an ADODB connection to a database

for the "how to generate random question"

here's my code: (its from my thesis , but ur free to use it :) )

Set conn = New ADODB.connection
prov = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\MAINDB2.mdb" & ";Persist Security Info=False"
conn.Open (prov), , , 0
    '"<conn string>"
    ' ***** (step 1) *****
    Set rs = conn.Execute("SELECT COUNT(Question) FROM QnE where fldChapter = 9")
    rCount = rs(0)
    ' ***** (step 2) *****
    Set rs = conn.Execute("SELECT Question FROM QnE where fldChapter = 9")
    cnt = 1
    Dim RRs
    ReDim RRs(rCount)
    Do While Not rs.EOF
        RRs(cnt) = rs(0)
        cnt = cnt + 1
    ' ***** (step 3) *****
    currentRR = CLng(Rnd * rCount + 0.5)
    ID = RRs(currentRR)
    ' ***** (step 4) *****
    sql = "SELECT * FROM QnE WHERE Question= '" & ID & "'"
    Set rs = conn.Execute(sql)
    Label1.Caption = ID
    Set rs = Nothing
    Set conn = Nothing

just change the destination field,table and database for the query

and 1 more thing, ID is a dim, and put 1 labelbox on the form

hope you gets something from this ^^

This article has been dead for over six months. Start a new discussion instead.