Quiz Code

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > VB Programming

Quiz Code

kvarnerexpress
I saw a nice quiz code posted by medialint where the questions and answers are written in the code. What I
need help with is adapting it so that it uses an access database or an excel csv file as the source of the questions and the choices. In the code itself there is a comment to the fact that "ideally they (meaning the Q's & A's) will be read from a database."
So how is that done? How do you get a quiz code to use a database?Also the table is fairly long and is divided and arranged in alphabetical order. Could the questions be limited to the info in the group of one letter of the alphabet at a time? Fopr example get the questions from
the letter A or B or both?

Reply

Galahad
Yes, you can get your quiz to use Access database, or any other for that matter...

To use Access DB, you can use either ADO, DAO or Data control... I prefer to use DAO 3.6, so I'll explaint it quickly...

Before everything, add a reference to Microsoft DAO 3.6 object. Next, you need to create Database object, that will hold the database, and create Recordset object, that holds actual table with questions and answers...
CODE
Dim DB As Database
Dim RS As Recordset

Then, proceed to open database and table
CODE
Set DB = OpenDatabase("databasename.mdb")
Set RS = DB.OpenRecordset("tablename")

Now, I prefer to use SQL for search operations inside database, so here's how you get a group of questions, based on a first letter for example. I assume you have some basic knowledge of SQL (Structured Query Language). Like with filenames, * is a wildcard, and SQL syntax is fairly easily understandable...
CODE
SQL="SELECT * FROM tablename WHERE question LIKE ""A*"""
Set RS = DB.OpenRecordset(SQL)

Now, you may have noticed I used OpenRecordset, to execute SQL... This is a great way to create a recordset object, containing search results in your SQL query... Now, it is not neccesary to open the entire table, if you will be searching for specific questions... If you have some basic knowledge of databases, you will handle this easily... Here's the portion of the code you could use (it's not tested, but it should work, just replace database, table and field names with your own):

CODE
Dim DB As Database
Dim RS As Recordset
Dim SQL As String
Private Sub Form_Load()
Set DB = OpenDatabase("database.mdb")
End Sub

Private Sub Command1_Click()
SQL = "SELECT * FROM TableName WHERE FieldName LIKE ""A*"""
Set RS = DB.OpenRecordset(SQL)
RS.MoveLast
RS.MoveFirst
If RS.RecordCount > 0 Then
 ' Write your code to handle the results
Else
 ' No matches found, what to do, write here
End If
End Sub


If you need further help, drop me an e-mail...

 

 

 


Reply

Galahad
Yes, you can get your quiz to use Access database, or any other for that matter...

To use Access DB, you can use either ADO, DAO or Data control... I prefer to use DAO 3.6, so I'll explaint it quickly...

Before everything, add a reference to Microsoft DAO 3.6 object. Next, you need to create Database object, that will hold the database, and create Recordset object, that holds actual table with questions and answers...
CODE
Dim DB As Database
Dim RS As Recordset

Then, proceed to open database and table
CODE
Set DB = OpenDatabase("databasename.mdb")
Set RS = DB.OpenRecordset("tablename")

Now, I prefer to use SQL for search operations inside database, so here's how you get a group of questions, based on a first letter for example. I assume you have some basic knowledge of SQL (Structured Query Language). Like with filenames, * is a wildcard, and SQL syntax is fairly easily understandable...
CODE
SQL="SELECT * FROM tablename WHERE question LIKE ""A*"""
Set RS = DB.OpenRecordset(SQL)

Now, you may have noticed I used OpenRecordset, to execute SQL... This is a great way to create a recordset object, containing search results in your SQL query... Now, it is not neccesary to open the entire table, if you will be searching for specific questions... If you have some basic knowledge of databases, you will handle this easily... Here's the portion of the code you could use (it's not tested, but it should work, just replace database, table and field names with your own):

CODE
Dim DB As Database
Dim RS As Recordset
Dim SQL As String
Private Sub Form_Load()
Set DB = OpenDatabase("database.mdb")
End Sub

Private Sub Command1_Click()
SQL = "SELECT * FROM TableName WHERE FieldName LIKE ""A*"""
Set RS = DB.OpenRecordset(SQL)
RS.MoveLast
RS.MoveFirst
If RS.RecordCount > 0 Then
 ' Write your code to handle the results
Else
 ' No matches found, what to do, write here
End If
End Sub


If you need further help, drop me an e-mail...

Reply

Galahad
I apologize for double post, I got "Cannot find server" page, and then I just hit the back button, and submited again... Please moderators, delete this, and the post before this... Sorry

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Recent Queries:-
  1. quizz mdb - 17.71 hr back. (1)
  2. vb coding for quiz system - 39.04 hr back. (1)
  3. quiz program using visual basic with database - 44.75 hr back. (2)
  4. php db quiz example - 54.99 hr back. (1)
  5. visual basic quiz programming - 61.96 hr back. (1)
  6. quiz code in vb - 64.50 hr back. (1)
  7. php source quiz game code - 65.95 hr back. (1)
  8. source code for quiz games - 72.31 hr back. (1)
  9. coding quiz - 45.80 hr back. (2)
  10. sample quiz source in php - 87.57 hr back. (1)
  11. example html quiz question code - 89.69 hr back. (1)
  12. vb source code for quiz - 93.92 hr back. (1)
  13. online quiz,sample code - 116.39 hr back. (1)
  14. source code for quiz in vb6 - 132.08 hr back. (2)
Similar Topics

Keywords : quiz code

  1. Find Prime Number - find prime number code (4)
  2. Best Vb Source Code Site - Best vb source code site (1)
    Are you looking vb code ! try this site >> http://www.planet-source-code.com ...



Looking for quiz, code

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for quiz, code

*MORE FROM TRAP17.COM*
advertisement



Quiz Code



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE