Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / July 2007

Tip: Looking for answers? Try searching our database.

Need your help: read text file

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
portCo - 30 Jul 2007 17:12 GMT
Hello there,

I am creating a vb application which is some like like a questionare.

Application read a text file which contains many questions and display
one question and the input is needed from user to calculate the score.

Here is a problem.

I can read a text file. However, it's read whole file at a time. So,
it only displays the last question.

Is there any way I can read one line from a text file and wait for a
user input and when user puts an answer and click next then read next
line and wait for a user input and so on.

Do you guys have any idea or hint that I can use?

Any input from you will be appreciated.

Thank you,
portCo - 30 Jul 2007 17:13 GMT
By the way, I am using Visual Basic 2005.

> Hello there,
>
[quoted text clipped - 17 lines]
>
> Thank you,
Lloyd Sheen - 30 Jul 2007 17:59 GMT
> Hello there,
>
[quoted text clipped - 17 lines]
>
> Thank you,

Assuming that the file contains one question per line you would do the
following :

Read you file as you do now into a string.  Then split the string on the
vbcrlf which should give you an array of strings.

Then loop thru you array displaying the question, waiting for the answer,
recording the answer and then going to the next question until the questions
are complete.

Hope this helps

Lloyd Sheen
portCo - 30 Jul 2007 19:14 GMT
Thank you for your input.

The file contains like

1. Is VB stand for Visual Bag?, F
2. 1. Is VB stand for Visual Basic?, T

I am confused and not sure about "waiting for the answer". How can I
wait for the answer before go into next question?

This is my question.

Thanks again

-portco

> > Hello there,
>
[quoted text clipped - 33 lines]
>
> - Show quoted text -
Lloyd Sheen - 31 Jul 2007 00:42 GMT
> Thank you for your input.
>
[quoted text clipped - 50 lines]
>>
>> - Show quoted text -

The loop asking questions would be implied not a "real" loop.  What you
would do is once you have finished reading and parsing (splitting) the file
you will display a question and wait for an answer.  The answer will be the
event that you then process the answer and see if there are more questions
to be asked.  If so then ask the next (and so on).  If the questions are
complete then you will .... do whatever it is you do with the results.

Hope this helps.
Lloyd Sheen
Cor Ligthert[MVP] - 30 Jul 2007 19:32 GMT
As you mean with a Text file a txt file, formely also called asci file or
whatever, than the answer is simple,

"No''  that is not possible.

You would have to use a binary file (formaly named a random file) or a
database.

However with so much memory today in every computer is the question in my
eyes a little bit sily and will the solution given by Lloyd be good  (and
fast) enough as that fits you.

Cor

> Hello there,
>
[quoted text clipped - 17 lines]
>
> Thank you,
Phil - 31 Jul 2007 13:44 GMT
> Is there any way I can read one line from a text file and wait for a
> user input and when user puts an answer and click next then read next
> line and wait for a user input and so on.

Dim Question As String
Dim Answer As String
FileOpen(1, Filename, OpenMode.Input)
While Not EOF(1)
   Question = LineInput(1)
   Answer=InputBox(Question)
End While
FileClose()

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.