Applying Object and components
this solution will accept 5 question either true or false or multiple choice, then will print the ouput to a file
so is one textbox for the question called txtq, and four for the snswers called txta1,txta2, txta3, txa4
three buttons one called BtnAddTrueFalse, BtnMultiple, and the other BtnPrint.
New questions will be stored in an array of type CQuestion.Each record will be instantiated as either CTrueFalse or CMultiple.To print the file you will loop through the array.
with the help of my book i came out with this code.. but appear not to be working.
can you check the code for the BtnAddTrueFalse and AddMultiple and print
Here is my code..
Public Class CMultiple
Inherits CQuestion
Private m1 As String
Private m2 As String
Private m3 As String
Private m4 As String
Public Sub New(ByVal qnum As Int16, ByVal question As String, ByVal a1 As String, ByVal a2 As String, ByVal a3 As String, ByVal a4 As String)
MyBase.mQuestionNumber = qnum
MyBase.mquestion = question
m1 = a1
m2 = a2
m3 = a3
m4 = a4
End Sub
Public Overrides Sub PrintQuestion(ByRef test As String)
End Sub
End Class
---------------------------------
Public Class CTrueFalse
Inherits CQuestion
Public Sub New(ByVal qnum As Int16, ByVal question As String)
MyBase.mQuestionNumber = qnum
MyBase.mquestion = question
End Sub
Public Overrides Sub PrintQuestion(ByRef test As String)
End Sub
End Class
---------------------------------------------------
Public MustInherit Class CQuestion
Protected mQuestionNumber As Int16
Protected mquestion As String
Public MustOverride Sub PrintQuestion(ByRef test As String)
End Class
------------------------------------------------
Public Class frmMain
Private arQ(4) As CQuestion
Private test As String
Private Sub frMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
test = "test"
test &= vbNewLine & vbNewLine
End Sub
Private Sub BtnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnAdd.Click
Dim qnum As Int16
If qnum < 5 Then
arQ(qnum) = New CTrueFalse(qnum + 1, TxtQuestion.Text)
qnum += 1
End If
End Sub
Private Sub BtnMultiple_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnMultiple.Click
Dim qnum As Int16
arQ(qnum) = New CMultiple(qnum + 1, TxtQuestion.Text, TxtA.Text, TxtB.Text, TxtC.Text, TxtD.Text)
End Sub
Private Sub BtnPrint_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnPrint.Click
Dim intX, intY As Integer
intY = arQ.Length
For intX = 0 To (intY - 1)
If arQ(intX) IsNot Nothing Then
arQ(intX).PrintQuestion(test)
End If
Next
MsgBox(test)
End Sub
End Class
|