PDA

View Full Version : Multiple choice exam template help



McDoug
08-16-2013, 12:38 PM
I am attempting to create a template for a series of exams. The exam has 20 question with 4 answers each and each answer is preceded by a option button.

I am trying to learn this on my own and have succeeded in coding a command button to clear all the (80) option buttons and a command button to print the exam.

I want to;
code a msg box to display the exam score,
code a command button for the student to "Save" a copy of the exam in his/her name and as a PDF.

Can anyone direct me to any tutorials that will help me with these?

Regards.

McDoug

Doug Robbins
08-16-2013, 10:03 PM
To come up with the exam score, it would be necessary to know which option button is the correct one for each answer.

For the saving as pdf, you use the ActiveDocument.ExportAsFixedFormat method.

To get the user name, see the article "How to get the username of the current user” at:

http://www.word.mvps.org/FAQs/MacrosVBA/GetCurUserName.htm

fumei
08-17-2013, 10:54 PM
Assuming of course each question is equally weighted in determining a score.

Doug Robbins
08-18-2013, 12:02 AM
Even then, you would still need to know which of the four possible answers to each question was the correct one.

McDoug
08-19-2013, 05:11 AM
Morning all.

First ... thank you for your reply's.

Second, remember, I do not have any formal training in VBA so my questions/assumptions may be wayyyyy of base here.

Regarding scoring, I have created 4 possible answers for each of the 20 questions and assigned a question grouping to each of those, for example,
the first possible answer for question 1 = (Name) OptionButton1, GroupName = q1.
the second possible answer for question 1 = (Name) OptionButton2, GroupName = q1, and so for all 4 possible answers of each question.
Questions 2 thru 20 just repeat with appropriate changes to the OptionButton number and GroupName.

So, would an If/Then statement (with the correct answer identified) directed to the answer value work?

Regards.

Doug Robbins
08-19-2013, 02:50 PM
So, if the names of the option buttons for question 1, for which you should use a Group Name of 01 (as you have more than 9 questions) were

Answer 1 - q011
Answer 2 - q012
Answer 3 - q013
Answer 4 - q014

How would you know which Answer was the correct answer. You need to know that to be able to score.

The VBA is not hard, it's the (lack of) logic that is the issue.

fumei
08-19-2013, 04:05 PM
"The VBA is not hard, it's the (lack of) logic that is the issue. "

I can not agree more. McDoug, coming up with good efficient VBA is in direct relation to how well you THINK. Logical thinking will deliver better code than any other factor. The actual CODE for each Option Button will be very very easy. The LOGIC of what they mean is where the work is. Once you figure out the logic of the process I am positive the actual coding will take only a few minutes.

For example, you have four button relating to question 1. Logically is it possible to have TWO legitimate answers? You do not say. If it is possible then there must be weighting of all possible answers. This is logic. If it is NOT possible, then logically if Option Button 2 (for question 1) is TRUE - but the correct answer is Option Button = True - then the Score for question 1 is 0 (I assume).

And so on.

McDoug
08-20-2013, 06:30 AM
Mr. Robbins / Mr Fumei.

Okay ... I've had a mini Ah ha moment (or stroke). After more reading of my "Mastering VBA" book, it appears that at least one of my assumptions was incorrect. I misunderstood the value properties of the OptionButton. I assumed that the value of a group was independent of the other OptioButtons in that group. My thinking was that if I changed the value (from false to true for example) for the "correct answer" than I should be able to do a simple calc to determine if the tester had selected the correct answer by displaying the score at the end of the test.

So, I need to read/understand more about the properties of the buttons so I can develop a logic that will work with the capability of the properties of the buttons or check boxes I use.

Thank you and regards to you. I'll be back.

McDoug

Doug Robbins
08-20-2013, 02:33 PM
I fear that you are still too focused on the VBA rather than the necessary logic.

You need to have some reference source that lists which is the correct answer for each question. Until you determine what that is going to be, any attention to the option button code is pointless.

If I were you, I would use an Excel workbook as the source with column A of a spreadsheet containing the question numbers and column B containing a number from 1 to 4 corresponding to the correct answer for each question.

Other things that you need to consider are where are you going to record the scores for each person taking the test? How will each person be identified from the document that contains their responses?

McDoug
08-21-2013, 08:20 AM
Mr Robbins,

I will be away from this for a little while, I've spent far too much time on the VBA part of this and need to finish creating the other parts of this program but I will as you suggested create the test template in Excel in preparation for my next attempt.

Thank you and regards.

SamT
08-21-2013, 06:35 PM
I was thinking about the logic of this as a sleep aide last night and I think it could be a very profitable App.

An Excel Workbook with multiple Sheets named after Test code Names.

Column "A" is the questions, "B" the correct answer, "C"-"X" the wrong answers.

Many Rows of Q & A'a, more than needed for any given test.

Both the Doc and the Workbook need an Array UDT(Num Q's) with Q, A1,thru A4 and Correct A number

Book code to fill UDT Array with Random Qs and Randomized Answers, including column "B" and any random n of "C" through X

A Book Property Get UDT(NumQuestions, NumAnswers, TestName)

Doc Code to Access Book and fill in Test

Good code would allow True/False questions and <=> 4 answers.

Since any hacker/cheater could memorize Column "B", place the correct answer in a random column and identify it with a custom font name. Multiple columns of random questions, only one of which applies. Heh! Get VBAX member snb to code it for you. :bug:

All MSO applications ignore uninstalled Fonts (Names) and use the default font.

Over time, an instructor could have several hundred questions and false answers per test

McDoug
08-22-2013, 08:00 AM
SamT,

Thank you for your reply, you've given me much to think about.

McDoug

Paul_Hossler
08-22-2013, 12:36 PM
I was thinking about the logic of this as a sleep aide last night



A variation on SamT's idea would be to structure your test bank for each subject on a different worksheet and in 2 columns.

Excel could then randomly select and arrange the desired number of questions for that subject, and randomly select and arrange the correct plus how ever many wrong answers you want

Options would be things like "how many questions", "up to how many possible answers", "what mix of hard / medium / easy" by adding another column, etc.

Paul

SamT
08-22-2013, 08:12 PM
HEY! I resemble Q19. Better watch what you say!

fumei
08-22-2013, 09:44 PM
"Excel could then randomly select and arrange the desired number of questions for that subject, and randomly select and arrange the correct plus how ever many wrong answers you want"

I think we are getting waaaay off the original subject here. There is no indication for a need for randomly selecting questions and answers.

McDoug, again, once you determine the logic the actual coding should be straight forward.

Doug Robbins
08-23-2013, 01:47 AM
Attached is a solution for you in the form of a macro enabled document - Exam.docm (as the forum does not allow uploading of a macro enabled template) It is suggested however that you open this file and save it as a macro enabled template in your templates folder,

When you create a document from the template, the document will contain 20 tables, in each of which the the question should be entered into the first row, the correct answer should be entered into the second row and the other three answers in the other rows of each table. When that has been done for each of the tables, run the MakeExam macro that is in the template and that will create a new document in which the rows containing the answers in each table will be randomised and the document will be protected for filling in forms. When the exam documents have been completed by each of the students, if they are then saved in a folder by themselves and the MarkExam macro is run, it will process each of the exam documents and create a table into the first column of which it will insert the name that the student has entered into the formfield in their exam document and into the second column, it will insert the score between 0 and 20 representing the number of correct answers.

Don't go clicking on the option buttons in the docm or (dotm) or the files produced as otherwise, you will need to access the properties dialog to set the value to false.

Doug Robbins
08-24-2013, 01:15 AM
There was an error in the code in the MarkExam macro for which the code should be:


Sub MarkExam()
Dim score As Long
Dim fd As FileDialog
Dim strFolder As String
Dim strFile As String
Dim DocTest As Document, docResults As Document
Dim Arow As Row
Set docResults = Documents.Add
With docResults
.Tables.Add range:=.range, NumRows:=1, NumColumns:=2
With .Tables(1)
.Cell(1, 1).range.Text = "Name"
.Cell(1, 2).range.Text = "Score"
End With
End With
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
With fd
.Title = "Select the folder that contains the Test Documents."
If .Show = -1 Then
strFolder = .SelectedItems(1) & "\"
Else
MsgBox "You did not select a folder."
Exit Sub
End If
End With
strFile = Dir$(strFolder & "*.doc*")
While strFile <> ""
Set DocTest = Documents.Open(strFolder & strFile)
score = 0
With DocTest
For i = 1 To .InlineShapes.Count
With .InlineShapes(i).OLEFormat.Object
If Right(.Name, 1) = 1 And .Value = True Then
score = score + 1
End If
End With
Next i
End With
Set Arow = docResults.Tables(1).Rows.Add
With Arow
.Cells(1).range.Text = DocTest.FormFields("StudentName").Result
.Cells(2).range.Text = score
End With
DocTest.Close wdDoNotSaveChanges
strFile = Dir$()
Wend
End Sub