|
-
Nov 14th, 2000, 11:41 AM
#1
Thread Starter
Junior Member
How would I do this, we are working on a program where questions are taken out of a text file and used in this trivia game we are making. Another problem we have to solve is how to store the number of question you are, or the point of the game you are in. Would you just use a static variable? Thanks for all the help
Drew
-
Nov 14th, 2000, 11:53 AM
#2
transcendental analytic
This will load all qwestions into an array of variable length strings:
Code:
'in declarations
Private Qwestions() as string
'loading procedure
Dim buffer as string
Open file for binary as 1
if lof(1) then
buffer=space(lof(1))
Get#1,,buffer
qwestions=split(buffer,vbcrlf)
end if
close 1
And you should use a private variable for score or public/global if you have several forms.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 15th, 2000, 10:17 AM
#3
Thread Starter
Junior Member
thanks kedeman
Now, how should I prepare the text file? Thanks
Drew
-
Nov 15th, 2000, 10:33 AM
#4
Lively Member
-
Nov 15th, 2000, 10:35 AM
#5
_______
<?>
kedaman:
Qwestions Payback: LOL
wandoprog
How do I do this?
What is happening?
Why?
the split breaks the file an each VBCrlf.
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 15th, 2000, 12:53 PM
#6
transcendental analytic
oh ouch! Sam, why do i have to learn FSO when i can do everything i need with VB? Might want to place a file control on the form instead which you can use Or why not implementing a loadtext method in every textbox label and anything so that you don't need to handle files in vb?
I know some ppl like a object oriented interface, but beginners might not. wandoprog, what do you mean by prepare the textfile?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 16th, 2000, 11:31 AM
#7
Thread Starter
Junior Member
when i say "prepare the text file" i mean how do you type in the information so that vb can open it, and use it.
would you do it like this...
"question1" , "Answer1"
"question2" , "Answer2"
i know that doesn't work, but how do you do it? thanks
Drew
-
Nov 16th, 2000, 11:54 AM
#8
_______
<?>
as for FileSystemObject, you are adding controls and
dll to your project. Vb adds enough on it's own without
add further undue garbage.
Code:
If using the split method you could use 2 files
QuestionFile:
How do I do this?
What is happening?
Why?
AnswerFile:
I don't know.
Not too much.
Anyone's guess as to why.
use the code above on both.
You now have 2 arrays of equal measure.
ArrayOne ArrayTwo
myQuestionOne(1) = myAnswer(1)
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Nov 16th, 2000, 03:03 PM
#9
Lively Member
Kedaman: every man to his own, I guess. I like FSO, and I'm not too keen on that Open file For Whatever As #1. Personal preference. I get your point though, and to be fair I think it'd be worth learning both methods and using them accordingly, depending on which one suited me best at the time.
-
Nov 16th, 2000, 04:12 PM
#10
Another method of opening.
Code:
Open "MyFile" For Input As #1
MyStr = Input(LOF(1), 1)
Close #1
-
Nov 16th, 2000, 04:20 PM
#11
Here is how you can retrieve the data in the text file in the form of Question,Answer and stroe them in an Array respectivly.
Add the following to a Form with 2 CommandButtons.
Code:
Private Question(5) As String
Private Answer(5) As String
Private Sub Command1_Click()
Dim tmp As String
Dim Var As Variant
Dim iCount As Integer
Open "C:\Windows\Desktop\MyFile.txt" For Input As #1
Do Until EOF(1)
DoEvents
Line Input #1, tmp
iCount = iCount + 1
Var = Split(tmp, ",")
Question(iCount) = Var(0)
Answer(iCount) = Var(1)
Loop
End Sub
Private Sub Command2_Click()
'Display the Questions ans Answers
For I = 0 To 5
Print Question(I)
Print Answer(I)
Print ""
Next I
End Sub
-
Nov 16th, 2000, 09:45 PM
#12
transcendental analytic
Don't use Input function to read the whole file, it's much faster to read it in binary, and it's also faster to split than read the file in input.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 17th, 2000, 11:07 AM
#13
Thread Starter
Junior Member
is there a snippet of code to...
convert something to binary? Thanks
drew
-
Nov 19th, 2000, 02:27 PM
#14
transcendental analytic
You don't need to worry about how your data is stored, just in what order it is, when you open binary files. Just use the code i gave you, it will split all the qwestions separated by carriage return line feeds, into Qwestions array.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|