Bubbalouie
Technical User
I'm trying to help out the Human Resources people by creating a little app that reads some of the tests they give. I need some help with the logic cause my brain is hurting after 3 days of illogical thinking. I'm reading a text file and dumping the contents into a listbox and it does that fine. I found the text file read code on some website and am trying to hack it to my purposes.
I declared variables in Option Explicit:
Dim Fname$, ff, Raw$, Cloc, Tmp$
Dim Rep, QuestNum, CurrQuest, NextQuest, LastQuest As Integer
and in the form load set them as follows:
CurrQuest = 0
LastQuest = 0
NextQuest = 1
What I would like for it to do is load the text file line by line into the listbox till it hits Question 2: and stop so the user can look at the question and possible answers/explanation. Then click a Command button, clear the listbox and see the next question. Right now, it loads the whole file from start to finish without ever stopping and I just can't figure out how to make it stop, let alone display one at a time on the click of the command button. I'm stripping the number out of the 'Question X:' line and trying to use that to keep track of which one I'm on and to stop loading, but I'm stuck.
yeah, i'm a total vb noob but this stuff is kinda cool...
This won't load right (line feeds???) but the HR tests load perfect. Format of questions is
QUESTION 1:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id elit diam, et lobortis magna. Nunc a elit leo, a faucibus tellus. Mauris commodo congue
tempus. Fusce ac lorem metus. Nam aliquet est vitae purus ultrices eget blandit velit feugiat. In fringilla, nisi ut pulvinar aliquam, quam tortor molestie
ligula, a aliquet nibh velit egestas quam. In vitae nulla est. Integer lobortis mollis aliquam. Duis malesuada, ante vitae facilisis convallis, nisl neque
tincidunt metus, sollicitudin ultrices justo dui in quam. Nullam euismod lectus tempor nibh hendrerit sagittis. Quisque nec ante odio, ut tincidunt dui.
Pellentesque scelerisque pulvinar sem quis tincidunt. Nullam leo dolor, venenatis et molestie ac, adipiscing sed sem. Aenean eu turpis eget purus tristique
cursus non nec ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non neque sed ipsum malesuada iaculis.
A. ALorem ipsum dolor sit amet, consectetur adipiscing elit.
B. BLorem ipsum dolor sit amet, consectetur adipiscing elit.
C. CLorem ipsum dolor sit amet, consectetur adipiscing elit.
D. DLorem ipsum dolor sit amet, consectetur adipiscing elit.
Answer: D
QUESTION 2:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id elit diam, et lobortis magna. Nunc a elit leo, a faucibus tellus. Mauris commodo congue
tempus. Fusce ac lorem metus. Nam aliquet est vitae purus ultrices eget blandit velit feugiat. In fringilla, nisi ut pulvinar aliquam, quam tortor molestie
ligula, a aliquet nibh velit egestas quam. In vitae nulla est. Integer lobortis mollis aliquam. Duis malesuada, ante vitae facilisis convallis, nisl neque
tincidunt metus, sollicitudin ultrices justo dui in quam. Nullam euismod lectus tempor nibh hendrerit sagittis. Quisque nec ante odio, ut tincidunt dui.
Pellentesque scelerisque pulvinar sem quis tincidunt. Nullam leo dolor, venenatis et molestie ac, adipiscing sed sem. Aenean eu turpis eget purus tristique
cursus non nec ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non neque sed ipsum malesuada iaculis.
A. ALorem ipsum dolor sit amet, consectetur adipiscing elit.
B. BLorem ipsum dolor sit amet, consectetur adipiscing elit.
C. CLorem ipsum dolor sit amet, consectetur adipiscing elit.
D. DLorem ipsum dolor sit amet, consectetur adipiscing elit.
E. None of the above
Answer: A
Explanation
Pellentesque a nunc neque. Proin sagittis feugiat ipsum sit amet fermentum. Pellentesque ut neque augue. Morbi eget sem libero. Sed convallis ullamcorper
lectus, posuere blandit risus dapibus id. Phasellus semper adipiscing sem a vestibulum. Quisque pulvinar ornare facilisis. Vivamus imperdiet felis at risus
gravida vehicula. Nullam lacinia laoreet pharetra. Nulla.
QUESTION 3:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id elit diam, et lobortis magna. Nunc a elit leo, a faucibus tellus. Mauris commodo congue
tempus. Fusce ac lorem metus. Nam aliquet est vitae purus ultrices eget blandit velit feugiat. In fringilla, nisi ut pulvinar aliquam, quam tortor molestie
ligula, a aliquet nibh velit egestas quam. In vitae nulla est. Integer lobortis mollis aliquam. Duis malesuada, ante vitae facilisis convallis, nisl neque
tincidunt metus, sollicitudin ultrices justo dui in quam. Nullam euismod lectus tempor nibh hendrerit sagittis. Quisque nec ante odio, ut tincidunt dui.
Pellentesque scelerisque pulvinar sem quis tincidunt. Nullam leo dolor, venenatis et molestie ac, adipiscing sed sem. Aenean eu turpis eget purus tristique
cursus non nec ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non neque sed ipsum malesuada iaculis.
A. ALorem ipsum dolor sit amet, consectetur adipiscing elit.
B. BLorem ipsum dolor sit amet, consectetur adipiscing elit.
C. CLorem ipsum dolor sit amet, consectetur adipiscing elit.
D. DLorem ipsum dolor sit amet, consectetur adipiscing elit.
Answer: D
QUESTION 4:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id elit diam, et lobortis magna. Nunc a elit leo, a faucibus tellus. Mauris commodo congue
tempus. Fusce ac lorem metus. Nam aliquet est vitae purus ultrices eget blandit velit feugiat. In fringilla, nisi ut pulvinar aliquam, quam tortor molestie
ligula, a aliquet nibh velit egestas quam. In vitae nulla est. Integer lobortis mollis aliquam. Duis malesuada, ante vitae facilisis convallis, nisl neque
tincidunt metus, sollicitudin ultrices justo dui in quam. Nullam euismod lectus tempor nibh hendrerit sagittis. Quisque nec ante odio, ut tincidunt dui.
Pellentesque scelerisque pulvinar sem quis tincidunt. Nullam leo dolor, venenatis et molestie ac, adipiscing sed sem. Aenean eu turpis eget purus tristique
cursus non nec ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non neque sed ipsum malesuada iaculis.
A. ALorem ipsum dolor sit amet, consectetur adipiscing elit.
B. BLorem ipsum dolor sit amet, consectetur adipiscing elit.
C. CLorem ipsum dolor sit amet, consectetur adipiscing elit.
D. DLorem ipsum dolor sit amet, consectetur adipiscing elit.
E. None of the above
Answer: A
Explanation
Pellentesque a nunc neque. Proin sagittis feugiat ipsum sit amet fermentum. Pellentesque ut neque augue. Morbi eget sem libero. Sed convallis ullamcorper
lectus, posuere blandit risus dapibus id. Phasellus semper adipiscing sem a vestibulum. Quisque pulvinar ornare facilisis. Vivamus imperdiet felis at risus
gravida vehicula. Nullam lacinia laoreet pharetra. Nulla.
Thanks In Advance for ANY Ideas!
I declared variables in Option Explicit:
Dim Fname$, ff, Raw$, Cloc, Tmp$
Dim Rep, QuestNum, CurrQuest, NextQuest, LastQuest As Integer
and in the form load set them as follows:
CurrQuest = 0
LastQuest = 0
NextQuest = 1
What I would like for it to do is load the text file line by line into the listbox till it hits Question 2: and stop so the user can look at the question and possible answers/explanation. Then click a Command button, clear the listbox and see the next question. Right now, it loads the whole file from start to finish without ever stopping and I just can't figure out how to make it stop, let alone display one at a time on the click of the command button. I'm stripping the number out of the 'Question X:' line and trying to use that to keep track of which one I'm on and to stop loading, but I'm stuck.
yeah, i'm a total vb noob but this stuff is kinda cool...
Code:
Private Sub Command2_Click()
List1.Clear
Fname$ = "C:\HR_Test1.txt"
ff = FreeFile
Open Fname$ For Binary As #ff
Raw$ = String$(LOF(ff), 0)
'Read the entire file in one operation and close it
Get #ff, 1, Raw$
Close #ff
ReDim Txt$(0)
Do
Cloc = InStr(Raw$, vbCrLf)
If Cloc > 0 Then 'Parse the data
ReDim Preserve Txt$(0 To UBound(Txt$) + 1)
Tmp$ = Left$(Raw$, Cloc - 1)
Txt$(UBound(Txt$)) = Tmp$
Else
Exit Do 'All data has been parsed
End If
Raw$ = Right$(Raw$, Len(Raw$) - (Len(Tmp$) + 2))
'on form load LastQuest and CurrQuest are set to 0, NextQuest is set to 1
'get current question number by stripping out number
'and converting string to int
If Left$(Tmp$, 8) = "QUESTION" Then 'And CurrQuest <> LastQuest Then
CurrQuest = Trim(Tmp$)
CurrQuest = Right(CurrQuest, 2)
CurrQuest = Left(CurrQuest, 1)
CurrQuest = Val(CurrQuest)
End If
'if current question number is >= than last question number
'and < than the next question add line
If Left$(Tmp$, 8) = "QUESTION" Then 'And (CurrQuest > LastQuest And CurrQuest <> NextQuest) Then ' And CurrQuest < NextQuest) Then
List1.AddItem Tmp$
'ElseIf Left$(Tmp$, 8) = "QUESTION" And (CurrQuest > LastQuest And CurrQuest < NextQuest) Then
End If
If Left$(Tmp$, 8) <> "QUESTION" Then 'And CurrQuest >= LastQuest Then
List1.AddItem Tmp$
LastQuest = CurrQuest
NextQuest = CurrQuest + 1
End If
Loop
End Sub
This won't load right (line feeds???) but the HR tests load perfect. Format of questions is
QUESTION 1:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id elit diam, et lobortis magna. Nunc a elit leo, a faucibus tellus. Mauris commodo congue
tempus. Fusce ac lorem metus. Nam aliquet est vitae purus ultrices eget blandit velit feugiat. In fringilla, nisi ut pulvinar aliquam, quam tortor molestie
ligula, a aliquet nibh velit egestas quam. In vitae nulla est. Integer lobortis mollis aliquam. Duis malesuada, ante vitae facilisis convallis, nisl neque
tincidunt metus, sollicitudin ultrices justo dui in quam. Nullam euismod lectus tempor nibh hendrerit sagittis. Quisque nec ante odio, ut tincidunt dui.
Pellentesque scelerisque pulvinar sem quis tincidunt. Nullam leo dolor, venenatis et molestie ac, adipiscing sed sem. Aenean eu turpis eget purus tristique
cursus non nec ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non neque sed ipsum malesuada iaculis.
A. ALorem ipsum dolor sit amet, consectetur adipiscing elit.
B. BLorem ipsum dolor sit amet, consectetur adipiscing elit.
C. CLorem ipsum dolor sit amet, consectetur adipiscing elit.
D. DLorem ipsum dolor sit amet, consectetur adipiscing elit.
Answer: D
QUESTION 2:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id elit diam, et lobortis magna. Nunc a elit leo, a faucibus tellus. Mauris commodo congue
tempus. Fusce ac lorem metus. Nam aliquet est vitae purus ultrices eget blandit velit feugiat. In fringilla, nisi ut pulvinar aliquam, quam tortor molestie
ligula, a aliquet nibh velit egestas quam. In vitae nulla est. Integer lobortis mollis aliquam. Duis malesuada, ante vitae facilisis convallis, nisl neque
tincidunt metus, sollicitudin ultrices justo dui in quam. Nullam euismod lectus tempor nibh hendrerit sagittis. Quisque nec ante odio, ut tincidunt dui.
Pellentesque scelerisque pulvinar sem quis tincidunt. Nullam leo dolor, venenatis et molestie ac, adipiscing sed sem. Aenean eu turpis eget purus tristique
cursus non nec ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non neque sed ipsum malesuada iaculis.
A. ALorem ipsum dolor sit amet, consectetur adipiscing elit.
B. BLorem ipsum dolor sit amet, consectetur adipiscing elit.
C. CLorem ipsum dolor sit amet, consectetur adipiscing elit.
D. DLorem ipsum dolor sit amet, consectetur adipiscing elit.
E. None of the above
Answer: A
Explanation
Pellentesque a nunc neque. Proin sagittis feugiat ipsum sit amet fermentum. Pellentesque ut neque augue. Morbi eget sem libero. Sed convallis ullamcorper
lectus, posuere blandit risus dapibus id. Phasellus semper adipiscing sem a vestibulum. Quisque pulvinar ornare facilisis. Vivamus imperdiet felis at risus
gravida vehicula. Nullam lacinia laoreet pharetra. Nulla.
QUESTION 3:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id elit diam, et lobortis magna. Nunc a elit leo, a faucibus tellus. Mauris commodo congue
tempus. Fusce ac lorem metus. Nam aliquet est vitae purus ultrices eget blandit velit feugiat. In fringilla, nisi ut pulvinar aliquam, quam tortor molestie
ligula, a aliquet nibh velit egestas quam. In vitae nulla est. Integer lobortis mollis aliquam. Duis malesuada, ante vitae facilisis convallis, nisl neque
tincidunt metus, sollicitudin ultrices justo dui in quam. Nullam euismod lectus tempor nibh hendrerit sagittis. Quisque nec ante odio, ut tincidunt dui.
Pellentesque scelerisque pulvinar sem quis tincidunt. Nullam leo dolor, venenatis et molestie ac, adipiscing sed sem. Aenean eu turpis eget purus tristique
cursus non nec ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non neque sed ipsum malesuada iaculis.
A. ALorem ipsum dolor sit amet, consectetur adipiscing elit.
B. BLorem ipsum dolor sit amet, consectetur adipiscing elit.
C. CLorem ipsum dolor sit amet, consectetur adipiscing elit.
D. DLorem ipsum dolor sit amet, consectetur adipiscing elit.
Answer: D
QUESTION 4:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla id elit diam, et lobortis magna. Nunc a elit leo, a faucibus tellus. Mauris commodo congue
tempus. Fusce ac lorem metus. Nam aliquet est vitae purus ultrices eget blandit velit feugiat. In fringilla, nisi ut pulvinar aliquam, quam tortor molestie
ligula, a aliquet nibh velit egestas quam. In vitae nulla est. Integer lobortis mollis aliquam. Duis malesuada, ante vitae facilisis convallis, nisl neque
tincidunt metus, sollicitudin ultrices justo dui in quam. Nullam euismod lectus tempor nibh hendrerit sagittis. Quisque nec ante odio, ut tincidunt dui.
Pellentesque scelerisque pulvinar sem quis tincidunt. Nullam leo dolor, venenatis et molestie ac, adipiscing sed sem. Aenean eu turpis eget purus tristique
cursus non nec ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer non neque sed ipsum malesuada iaculis.
A. ALorem ipsum dolor sit amet, consectetur adipiscing elit.
B. BLorem ipsum dolor sit amet, consectetur adipiscing elit.
C. CLorem ipsum dolor sit amet, consectetur adipiscing elit.
D. DLorem ipsum dolor sit amet, consectetur adipiscing elit.
E. None of the above
Answer: A
Explanation
Pellentesque a nunc neque. Proin sagittis feugiat ipsum sit amet fermentum. Pellentesque ut neque augue. Morbi eget sem libero. Sed convallis ullamcorper
lectus, posuere blandit risus dapibus id. Phasellus semper adipiscing sem a vestibulum. Quisque pulvinar ornare facilisis. Vivamus imperdiet felis at risus
gravida vehicula. Nullam lacinia laoreet pharetra. Nulla.
Thanks In Advance for ANY Ideas!