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?

hmmm...

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
        rs.MoveNext
    Loop
 
    ' ***** (step 3) *****
 
    Randomize
    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
  
    
    rs.Close
    Set rs = Nothing
    conn.Close
    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 ^^

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.