| | |
VB 6.0 file manipulation prob...
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2006
Posts: 48
Reputation:
Solved Threads: 0
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.
#problem2
for the same form
The error: Compile error ->method or data member not found
#problem3
This is also for the same form
Th error: Compile time error -> path not found
Thank you every body in advance
Embeza
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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
Last edited by Comatose; Jul 21st, 2006 at 7:10 pm. Reason: Removed Bold Abundancy, and Added Code Tags
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.
•
•
Join Date: Jun 2006
Posts: 48
Reputation:
Solved Threads: 0
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
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
Last edited by Embeza; Jul 23rd, 2006 at 4:47 am.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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?
•
•
Join Date: Jun 2006
Posts: 48
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Comatose
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
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?
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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Open filepath For Output As #filenum Print #filenum, textToWrite Close #filenum
•
•
Join Date: Jun 2006
Posts: 48
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Comatose
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:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Open filepath For Output As #filenum Print #filenum, textToWrite Close #filenum
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.
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.
•
•
Join Date: Jun 2006
Posts: 48
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by Comatose
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.
So do you any any other featire of VB 6.0 used to manipulate a file from the beginning?
![]() |
Similar Threads
- File I/O Manipulation Prob (Java)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: How to temporarily disable Sound Card/Driver
- Next Thread: Invalid Inside / Outside Procedure
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex age append application basic beginner birth bmp c++ calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver struct subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






