Click to See Complete Forum and Search --> : Inputting a Sequential file Into a array


Drew
March 17th, 2001, 12:32 AM
I have this text file to Input as a sequential Access File

Data-types Quiz, 8
1, What data-type would you use for the population of Chicago?, LONG,LONG,lng,1
2, What data-type would you use for a Social Security number?, STRING,STRING,str,1
3, What data-type would you use for a variable where the only valid values are ON/OFF?, BOOLEAN,BOOLEAN,bln,1
4, What data-type would you use for a constant with a value for Pi?, SINGLE,SINGLE,sng,1
5, What data-type would you use for a variable to hold the grains of sand on a beach?, DOUBLE,DOUBLE,dbl,1
6, "What initial should proceed a Public variable in a module to indicate its scope?
a. p
b. g
c. m
d. No initial", B,G,"B. g",5
7, "What initial should proceed a variable that is used in a form to indicate its scope?
a. p
b. g
c. m
d. No initial", C,M,"C. M",5
8, "What initial should proceed a variable that is used in a local procedure to indicate its scope?
a. p
b. g
c. m
d. No initial", D,NO INITIAL,"D. NO INITIAL",5

I have this code so far that has a control array to make command Buttons
for each question.

Option Explicit
Dim q_strQuestionsAndAnswers() As String
'This will display the command buttons
Private Sub cmdDisplay_Click(intIndex As Integer)

lblQuestion.Caption = g_strQuestionsAndAnswers(2, intIndex)
txtInputbox.SetFocus
End Sub

Private Sub cmdDisplay_GotFocus(Index As Integer)
cmdDisplay(Index).BackColor = vbYellow
End Sub

Private Sub cmdDisplay_LostFocus(Index As Integer)
cmdDisplay(Index).BackColor = vbRed
End Sub

'This will ask the user if they want to end the program.
Private Sub cmdEndprogram_Click()
Dim intResponse As Integer
Const conPrompt As String = "Are you sure?"
Const conTitle As String = "Quit?"
intResponse = MsgBox(conPrompt, vbYesNo + vbQuestion, conTitle)
If intResponse = vbYes Then
Unload Me

End If
End Sub



'This is the main form code to show the splash screen and input the file
'name as well as the control array size.
Private Sub Form_Load()
Dim strFileName As String, strQuestions As String, strQuestionNumber As String
Dim intFileNum As Integer, name As String
Dim strFilter As String, NumberCorrect As Integer
Dim intNumberOfQuestions As Integer
Dim intLoadQuestions As Integer
Dim intLoadFields As Integer
Dim strTestName As String
Dim prompt As String, strAnswere1 As String
Dim strAnswere2 As String, strAnswere3 As String
Dim title As String



'frmQuizzerSplash.Show vbModal
prompt = "Enter your Name."
title = "Your Name"
name = InputBox(prompt, title)

intFileNum = FreeFile
strFilter = "Text Files (*.txt)|*.txt|" & "All files (*.*)|*.*"
cdlOpenfile.Filter = strFilter
cdlOpenfile.ShowOpen
strFileName = cdlOpenfile.FileName
'On Error GoTo FileOpenErr
Open strFileName For Input As #intFileNum
Input #intFileNum, strTestName, intNumberOfQuestions ', strQuestionNumber, strQuestions, strAnswere1, strAnswere2, strAnswere3

'Me.Caption = strTestName

ReDim g_strQuestionsAndAnswers(1 To 6, 1 To intNumberOfQuestions) As String

For intLoadQuestions = 1 To intNumberOfQuestions
Call MakeTheButtons(intLoadQuestions)
For intLoadFields = 1 To 6
Input #intFileNum, g_strQuestionsAndAnswers(intLoadFields, intLoadQuestions)
Next intLoadFields
Next intLoadQuestions

Close #intFileNum


End Sub


'This will output the Queston to the user
Private Sub lblQuestion_Click()

End Sub
'This will tell the user about the program.
Private Sub mnuabout_Click()
frmInformation_Screen.Show
End Sub
'This procedure will end the program
Private Sub mnudone_Click()
End
End Sub

'This will give infprmation about the computer system and the program
Private Sub mnuinformation_Click()
frmAbout.Show vbModal
End Sub
'This is the input box so the user can type in the answere
Private Sub txtInputbox_GotFocus()
txtInputbox.SelStart = 0
txtInputbox.SelLength = Len(txtInputbox.Text)
End Sub
'This procedure will make the buttons for each question
Private Sub MakeTheButtons(ByVal intLoadQuestions As Integer)
Load cmdDisplay(intLoadQuestions)

cmdDisplay(0).Visible = False
cmdDisplay(intLoadQuestions).Visible = True
cmdDisplay(intLoadQuestions).Caption = intLoadQuestions

Select Case intLoadQuestions
Case Is <= 10


cmdDisplay(intLoadQuestions).Left = cmdDisplay(0).Left + cmdDisplay(0).Width * intLoadQuestions


If intLoadQuestions = 1 Then
cmdDisplay(intLoadQuestions).Left = cmdDisplay(1).Left
Else
cmdDisplay(intLoadQuestions).Left = cmdDisplay(0).Left + cmdDisplay(0).Width * intLoadQuestions
End If
Case Is <= 20
If intLoadQuestions = 11 Then
cmdDisplay(11).Left = cmdDisplay(0).Left
Else
cmdDisplay(intLoadQuestions).Left = cmdDisplay(intLoadQuestions - 1).Left + _
cmdDisplay(0).Width
End If
cmdDisplay(intLoadQuestions).Top = cmdDisplay(0).Top + cmdDisplay(0).Height
Case Else
If intLoadQuestions = 21 Then
cmdDisplay(21).Left = cmdDisplay(0).Left
Else
cmdDisplay(intLoadQuestions).Left = cmdDisplay(intLoadQuestions - 1).Left + cmdDisplay(0).Width
End If
cmdDisplay(intLoadQuestions).Top = cmdDisplay(0).Top + 2 * (cmdDisplay(0).Height)
End Select


End Sub

I can't correctly Input the answeres and compare them to the answere in
the text box. I want to enter the answeres in a array as well but I
have tried several different things and I can't get it wright.
Any Suggestions?