VB 6.0 file manipulation prob...

Reply

Join Date: Jun 2006
Posts: 48
Reputation: Embeza is an unknown quantity at this point 
Solved Threads: 0
Embeza Embeza is offline Offline
Light Poster

VB 6.0 file manipulation prob...

 
0
  #1
Jul 21st, 2006
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.
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub cmdappend_Click()
  2. Dim filenum As Integer
  3. Dim filepath As String
  4. Dim textToWrite As String
  5. textToWrite = txtwrite.Text
  6. filenum = FreeFile()
  7. filepath = txtpath.Text
  8. Open filepath For Output As #filenum
  9. While EOF(filenum)
  10. Print #filenum, textToWrite
  11. Wend
  12. Close #filenum
  13. 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)
  1. Private Sub cmdread_Click()
  2. Dim filenum As Integer
  3. Dim filepath As String
  4. Dim textToDisplay As String
  5. filenum = FreeFile()
  6. filepath = txtpath.Text
  7. Open filepath For Input As #filenum
  8. While Not EOF(filenum)
  9. Input #filenum, textToDisplay
  10. Wend
  11. txtoutput.Text = textToDisplay
  12. Close #filenum
  13. 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)
  1. Private Sub cmdwrite_Click()
  2. Dim msg As String
  3. Dim filenum As Integer
  4. Dim filepath As String
  5. Dim textToWrite As String
  6. textToWrite = txtwrite.Text
  7. filenum = FreeFile()
  8. filepath = txtpath.Text
  9. msg = "Do you want to cancel previous data in"
  10. MsgBox msg + filepath + "?", vbOKCancel, "Pay Attention Embeza!"
  11. 'if vbOkCancel=Ok then continue. Dont otherwise
  12. Open filepath For Output As #filenum
  13. While BOF(filenum)
  14. Print #filenum, textToWrite
  15. Wend
  16. Close #filenum
  17. End Sub


Thank you every body in advance
Embeza
Last edited by Comatose; Jul 21st, 2006 at 6:10 pm. Reason: Removed Bold Abundancy, and Added Code Tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 212
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: VB 6.0 file manipulation prob...

 
0
  #2
Jul 21st, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 48
Reputation: Embeza is an unknown quantity at this point 
Solved Threads: 0
Embeza Embeza is offline Offline
Light Poster

Re: VB 6.0 file manipulation prob...

 
0
  #3
Jul 23rd, 2006
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
Last edited by Embeza; Jul 23rd, 2006 at 3:47 am.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 212
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: VB 6.0 file manipulation prob...

 
0
  #4
Jul 23rd, 2006
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Open filepath For Output As #filenum
  2. While BOF(filenum)
  3. Print #filenum, textToWrite
  4. Wend
  5. Close #filenum

How many times are you trying to write the variable "textToWrite" to the file?
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 48
Reputation: Embeza is an unknown quantity at this point 
Solved Threads: 0
Embeza Embeza is offline Offline
Light Poster

Re: VB 6.0 file manipulation prob...

 
0
  #5
Jul 23rd, 2006
Originally Posted by Comatose
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Open filepath For Output As #filenum
  2. While BOF(filenum)
  3. Print #filenum, textToWrite
  4. Wend
  5. 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
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 212
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: VB 6.0 file manipulation prob...

 
0
  #6
Jul 23rd, 2006
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)
  1. Open filepath For Output As #filenum
  2. Print #filenum, textToWrite
  3. Close #filenum
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 48
Reputation: Embeza is an unknown quantity at this point 
Solved Threads: 0
Embeza Embeza is offline Offline
Light Poster

Re: VB 6.0 file manipulation prob...

 
0
  #7
Jul 23rd, 2006
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)
  1. Open filepath For Output As #filenum
  2. Print #filenum, textToWrite
  3. Close #filenum
I mean why I couldn't see the content of txtTowrite repeated in my text file?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 212
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: VB 6.0 file manipulation prob...

 
0
  #8
Jul 23rd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 48
Reputation: Embeza is an unknown quantity at this point 
Solved Threads: 0
Embeza Embeza is offline Offline
Light Poster

Re: VB 6.0 file manipulation prob...

 
0
  #9
Jul 24th, 2006
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.
Good,
So do you any any other featire of VB 6.0 used to manipulate a file from the beginning?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum


Views: 5350 | Replies: 8
Thread Tools Search this Thread



Tag cloud for Visual Basic 4 / 5 / 6
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC