bob saget
asked on
do while loop for putting information in a text file
i have a text file inside my bin-debug file ( its empty). my code is supposed to be a do while loop, and when the user presses a button they are supposed to enter 3 words in, once they do they that, those words will be inputted inside my code, this is my code right here. when it runs, it won't output the letters, and it will stay in an infinite loop.
Dim myfile As IO.StreamWriter = IO.File.CreateText("questi on2.txt")
Dim questfile As Double
questfile = CDbl(InputBox("enter 3 words to be outputed in a text file: enter -1 to stop"))
Do While CDbl(questfile) <> -1
myfile.WriteLine(questfile )
questfile = CDbl(InputBox("enter 3 words to be outputed in a text file: enter -1 to stop"))
Loop
myfile.Close()
Dim myfile As IO.StreamWriter = IO.File.CreateText("questi
Dim questfile As Double
questfile = CDbl(InputBox("enter 3 words to be outputed in a text file: enter -1 to stop"))
Do While CDbl(questfile) <> -1
myfile.WriteLine(questfile
questfile = CDbl(InputBox("enter 3 words to be outputed in a text file: enter -1 to stop"))
Loop
myfile.Close()
ASKER
how would i do it so if i entered a letter it would transfer it to the text file?
To your question, "how would i do it so if i entered a letter it would transfer it to the text file? ", Letters or words? How do you want it to show up in the file?
ASKER
words. But does it matter if i enter a single letter or a word?
To the question, "words. But does it matter if i enter a single letter or a word? " it only matters how you want it to be written to the text file, for example one character per line or word per line or maybe everything on one line?
ASKER
word per line
ASKER
this code works, but how can i put this is a loop?
Dim MYfile As String = "question2.txt"
If System.IO.File.Exists(MYfi le) = True Then
Dim writer As New System.IO.StreamWriter(MYf ile)
writer.Write(InputBox("ent er 3 words to be outputed in a text file: enter -1 to stop"))
writer.Close()
MessageBox.Show("Text written to file")
Else
MessageBox.Show("File Does Not Exist")
Dim MYfile As String = "question2.txt"
If System.IO.File.Exists(MYfi
Dim writer As New System.IO.StreamWriter(MYf
writer.Write(InputBox("ent
writer.Close()
MessageBox.Show("Text written to file")
Else
MessageBox.Show("File Does Not Exist")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thx for your help
Not a problem Bob, glad to help.
Please see my comments in your code
Open in new window