Hi every body
Can you please fix me errors.
Here are my codes and errors incountered

#Stage1
I want the user to type in the file path to txtpath.Text
and a text input to be appended to that file be written in txtwrite.Text
The error: Run Time error ->path not found
Don't hesitate on the file path. The file is definitely present.

Private Sub cmdappend_Click()
Dim filenum As Integer
Dim filepath As String
Dim textToWrite As String
textToWrite = txtwrite.Text
filenum = FreeFile()
filepath = txtpath.Text
Open filepath For Output As #filenum
   While EOF(filenum)
    Print #filenum, textToWrite
   Wend
 Close #filenum
End Sub

#problem2
for the same form
The error: Compile error ->method or data member not found

Private Sub cmdread_Click()
Dim filenum As Integer
Dim filepath As String
Dim textToDisplay As String
filenum = FreeFile()
filepath = txtpath.Text
Open filepath For Input As #filenum
   While Not EOF(filenum)
    Input #filenum, textToDisplay
   Wend
   txtoutput.Text = textToDisplay
 Close #filenum
End Sub

#problem3
This is also for the same form
Th error: Compile time error -> path not found

Private Sub cmdwrite_Click()
Dim msg As String
Dim filenum As Integer
Dim filepath As String
Dim textToWrite As String
textToWrite = txtwrite.Text
filenum = FreeFile()
filepath = txtpath.Text
msg = "Do you want to cancel previous data in"
MsgBox msg + filepath + "?", vbOKCancel, "Pay Attention Embeza!"
'if vbOkCancel=Ok then continue. Dont otherwise
Open filepath For Output As #filenum
   While BOF(filenum)
    Print #filenum, textToWrite
   Wend
 Close #filenum
End Sub

Thank you every body in advance;)
Embeza

Recommended Answers

All 8 Replies

1. Remove the While Wend, You aren't reading the file, therefore have no need to loop through it.... just write the variable. If you "appending" the data, as you stated above, you'll need to open the file for append, and not output, since output will over-write anything in the file, for the new information. See if it fixes either of the other 2.

Hello baddy,
i thank you for the reply.
The case that I placed "output" instead of "append" was a clear fault
but I doubt about the while ... wend.
while reading the system has to loop b/c it is reading all characters
of the text file until it reaches EOF.
I am sorry I haven't yet tried it for my PC is not currently working.
Thank you

Open filepath For Output As #filenum
   While BOF(filenum)
    Print #filenum, textToWrite
   Wend
Close #filenum

How many times are you trying to write the variable "textToWrite" to the file?

Open filepath For Output As #filenum
   While BOF(filenum)
    Print #filenum, textToWrite
   Wend
Close #filenum

How many times are you trying to write the variable "textToWrite" to the file?

Thank you .
I understand you now.
I don't need while...wend
But it acn't write any using while ... wend
Why do u think?
with regards

You are trying to write the contents of variable "textToWrite" to a file. So, you only need to write it once. The only time you might need to write it more than once is if the variable will change (for example, you are copying data from 1 file to another), but this code will work fine:

Open filepath For Output As #filenum
    Print #filenum, textToWrite
Close #filenum

You are trying to write the contents of variable "textToWrite" to a file. So, you only need to write it once. The only time you might need to write it more than once is if the variable will change (for example, you are copying data from 1 file to another), but this code will work fine:

Open filepath For Output As #filenum
    Print #filenum, textToWrite
Close #filenum

I mean why I couldn't see the content of txtTowrite repeated in my text file?;)

Oh!

Well, you see, BOF isn't a valid function (not built into VB anyway). So when you try to call it with your while loop, it flips out. BOF is supposed to be Begining of File, but (as far as I can tell) it only works as a property of a database object..... such as access or SQL (for more on doing that http://www.timesheetsmts.com/adotutorial.htm). Since you are just opening a sequential file, BOF is not recognized by VB, and therefore causes a problem that crashes the app, which stops it from writing at all.

Oh!

Well, you see, BOF isn't a valid function (not built into VB anyway). So when you try to call it with your while loop, it flips out. BOF is supposed to be Begining of File, but (as far as I can tell) it only works as a property of a database object..... such as access or SQL (for more on doing that http://www.timesheetsmts.com/adotutorial.htm). Since you are just opening a sequential file, BOF is not recognized by VB, and therefore causes a problem that crashes the app, which stops it from writing at all.

Good,
So do you any any other featire of VB 6.0 used to manipulate a file from the beginning?:?:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.