Jul 26, 2008

Quiz Code

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > VB Programming

free web hosting

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.
Confirm Code:

Recent Queries:-
  1. quizz code source - 21.96 hr back. (1)
  2. vb quiz project code - 37.79 hr back. (1)
  3. coding for quiz in vb - 41.81 hr back. (1)
  4. simple vb quiz coding - 42.16 hr back. (1)
  5. source code quiz to visual basic 6 - 44.52 hr back. (1)
  6. quiz sql query database - 45.08 hr back. (2)
  7. vb program code for quiz questions - 70.17 hr back. (1)
  8. vb quiz code - 25.24 hr back. (2)
  9. basic queries quiz(sql) - 103.23 hr back. (1)
  10. vb quiz example - 105.65 hr back. (4)
  11. database basic quiz - 121.34 hr back. (1)
  12. quiz in vb - 140.25 hr back. (1)
  13. sql quiz - 155.48 hr back. (1)
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 ....

    1. Looking for quiz, code

Searching Video's for quiz, code
advertisement



Quiz Code



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
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