B
bgmeindl
I'm having a problem with a string array and can't for the life of me
figure out what's going wrong.
I am creating a generic multiple choice/multiple answer slide that I
can then use for quizzes, etc.
I start by opening the text file for reading.
I then read the number of available questions [NumberOfQuestions =
Val(ts.readline)] [this is the first entry in the text file].
I then cycle through the number of available questions and fill a
series of arrays:
The first array holds the question itself [QuestionsArray(x) =
ts.readline 'question].
The second array holds the number of possible answers that will be
listed [QuestionSettingsArray(x, 0) = Val(ts.readline) 'number of
possible answers (max=5)]
The third array holds each of the possible answers
[PossibilitiesArray(x * 1) = ts.readline 'one of 5 possible answers]
[there are 5 of these statements to ensure that all possible answers
are read]
The fourth array holds whether the possible answer is correct or
incorrect [QuestionSettingsArray(x, 1) = Val(ts.readline) 'is this a
correct answer (1=correct; 0=incorrect)]
All of this goes swimmingly. However...
Once I have finished reading the text file and look to check my
PossibilitiesArray() the elements seem to be all over the place.
I have tested that the array is reading and placing the elements
correctly through the For...Next loop and everything seems to be ok. As
long as I am reading out of the array right away, there doesn't seem to
be a problem.
I'm going nuts here... and I can't seem to figure it out. I'm hoping
someone can help.
Thanks in advance for your time and energy on this.
Bob
Here is the entire sub (the msgbox statements are my tests to see
what's going on - they will also show you my problem - in the resulting
dialog the top portion should match the portion below the line):
--------CODE---------------
Sub Read_Data_From_File()
'use commented sections for writing data to a file
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts
Dim s As String
Dim y As Integer
Dim x As Integer
Set fs = CreateObject("Scripting.FileSystemObject")
'fs.CreateTextFile "test1.txt" 'Create a file
Set f = fs.GetFile("MC.txt")
'Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
'ts.Write "Hello World"
'ts.Close
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Dim TextMessage2 As String
Dim TestMessage As String
NumberOfQuestions = Val(ts.readline)
For x = 1 To NumberOfQuestions
QuestionsArray(x) = ts.readline 'question
QuestionSettingsArray(x, 0) = Val(ts.readline) 'number of
possible answers (max=5)
PossibilitiesArray(x * 1) = ts.readline 'one of 5 possible
answers
QuestionSettingsArray(x, 1) = Val(ts.readline) 'is this a
correct answer (1=correct; 0=incorrect)
PossibilitiesArray(x * 2) = ts.readline 'another of the
possible answers
QuestionSettingsArray(x, 2) = Val(ts.readline) 'is this a
correct answer
PossibilitiesArray(x * 3) = ts.readline 'another of the
possible answers
QuestionSettingsArray(x, 3) = Val(ts.readline) 'is this a
correct answer
PossibilitiesArray(x * 4) = ts.readline 'another of the
possible answers
QuestionSettingsArray(x, 4) = Val(ts.readline) 'is this a
correct answer
PossibilitiesArray(x * 5) = ts.readline 'another possible
answer
TextMessage2 = TextMessage2 & PossibilitiesArray(x * 2) & vbCrLf
QuestionSettingsArray(x, 5) = Val(ts.readline) 'is this a
correct answer
Next
For y = 1 To 5
TestMessage = TestMessage & PossibilitiesArray(y * 2) & vbCrLf
Next
MsgBox TestMessage & vbCrLf & "-------------" & vbCrLf & TextMessage2
ts.Close
End Sub
-------------End Code------------
for further information, here is the text file I am reading:
-----------Beginning of Text file-----------
5
A PDP...
4
Approves market and customer impacting initiatives
1
Ensures company wide communication
1
Is a legal document that meets Sarbanes Oxley and other regulatory
guidelines
1
Is really not that important
0
0
Which of the following is NOT a reason for having PDPs?
4
Keep everyone up to date
0
Increase stress on Rogers' employees
1
Support shareholders
0
Ensure a positive customer experience
0
0
Which is the third step in the PDP process?
5
1-Page Summary
0
Cross-Functional Pre-Work
0
Approvals
1
Implementation
0
Launch
0
What is the average time for a standard PDP from submission to launch?
4
Six days
0
Six weeks
1
Six months
0
Who knows?!
0
0
On the PDP Summary page of pdp.rogers.com you can find...
4
Program launch date
1
Final Approval level
1
Approval status of a program
1
The PDP business case
0
0
------------------End of text File------------
figure out what's going wrong.
I am creating a generic multiple choice/multiple answer slide that I
can then use for quizzes, etc.
I start by opening the text file for reading.
I then read the number of available questions [NumberOfQuestions =
Val(ts.readline)] [this is the first entry in the text file].
I then cycle through the number of available questions and fill a
series of arrays:
The first array holds the question itself [QuestionsArray(x) =
ts.readline 'question].
The second array holds the number of possible answers that will be
listed [QuestionSettingsArray(x, 0) = Val(ts.readline) 'number of
possible answers (max=5)]
The third array holds each of the possible answers
[PossibilitiesArray(x * 1) = ts.readline 'one of 5 possible answers]
[there are 5 of these statements to ensure that all possible answers
are read]
The fourth array holds whether the possible answer is correct or
incorrect [QuestionSettingsArray(x, 1) = Val(ts.readline) 'is this a
correct answer (1=correct; 0=incorrect)]
All of this goes swimmingly. However...
Once I have finished reading the text file and look to check my
PossibilitiesArray() the elements seem to be all over the place.
I have tested that the array is reading and placing the elements
correctly through the For...Next loop and everything seems to be ok. As
long as I am reading out of the array right away, there doesn't seem to
be a problem.
I'm going nuts here... and I can't seem to figure it out. I'm hoping
someone can help.
Thanks in advance for your time and energy on this.
Bob
Here is the entire sub (the msgbox statements are my tests to see
what's going on - they will also show you my problem - in the resulting
dialog the top portion should match the portion below the line):
--------CODE---------------
Sub Read_Data_From_File()
'use commented sections for writing data to a file
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Dim fs, f, ts
Dim s As String
Dim y As Integer
Dim x As Integer
Set fs = CreateObject("Scripting.FileSystemObject")
'fs.CreateTextFile "test1.txt" 'Create a file
Set f = fs.GetFile("MC.txt")
'Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
'ts.Write "Hello World"
'ts.Close
Set ts = f.OpenAsTextStream(ForReading, TristateUseDefault)
Dim TextMessage2 As String
Dim TestMessage As String
NumberOfQuestions = Val(ts.readline)
For x = 1 To NumberOfQuestions
QuestionsArray(x) = ts.readline 'question
QuestionSettingsArray(x, 0) = Val(ts.readline) 'number of
possible answers (max=5)
PossibilitiesArray(x * 1) = ts.readline 'one of 5 possible
answers
QuestionSettingsArray(x, 1) = Val(ts.readline) 'is this a
correct answer (1=correct; 0=incorrect)
PossibilitiesArray(x * 2) = ts.readline 'another of the
possible answers
QuestionSettingsArray(x, 2) = Val(ts.readline) 'is this a
correct answer
PossibilitiesArray(x * 3) = ts.readline 'another of the
possible answers
QuestionSettingsArray(x, 3) = Val(ts.readline) 'is this a
correct answer
PossibilitiesArray(x * 4) = ts.readline 'another of the
possible answers
QuestionSettingsArray(x, 4) = Val(ts.readline) 'is this a
correct answer
PossibilitiesArray(x * 5) = ts.readline 'another possible
answer
TextMessage2 = TextMessage2 & PossibilitiesArray(x * 2) & vbCrLf
QuestionSettingsArray(x, 5) = Val(ts.readline) 'is this a
correct answer
Next
For y = 1 To 5
TestMessage = TestMessage & PossibilitiesArray(y * 2) & vbCrLf
Next
MsgBox TestMessage & vbCrLf & "-------------" & vbCrLf & TextMessage2
ts.Close
End Sub
-------------End Code------------
for further information, here is the text file I am reading:
-----------Beginning of Text file-----------
5
A PDP...
4
Approves market and customer impacting initiatives
1
Ensures company wide communication
1
Is a legal document that meets Sarbanes Oxley and other regulatory
guidelines
1
Is really not that important
0
0
Which of the following is NOT a reason for having PDPs?
4
Keep everyone up to date
0
Increase stress on Rogers' employees
1
Support shareholders
0
Ensure a positive customer experience
0
0
Which is the third step in the PDP process?
5
1-Page Summary
0
Cross-Functional Pre-Work
0
Approvals
1
Implementation
0
Launch
0
What is the average time for a standard PDP from submission to launch?
4
Six days
0
Six weeks
1
Six months
0
Who knows?!
0
0
On the PDP Summary page of pdp.rogers.com you can find...
4
Program launch date
1
Final Approval level
1
Approval status of a program
1
The PDP business case
0
0
------------------End of text File------------