473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

why bad file error occur

kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1. Public Sub ReWrite_Open_File(ByVal FileNo As Long)
  2. Dim FileSize As Long, Buffer() As Byte
  3. ' PART 1: Read the file.
  4. FileSize = LOF(FileNo) ' Determine how large the file is (in bytes).
  5. ReDim Buffer(1 To FileSize) ' Set our buffer to that length.
  6. Get #FileNo, 1, Buffer() ' Grab the entire file's data into the array
  7. ' PART 2
  8. ' If you plan to change the data, this is where it would happen.
  9. 'Beep
  10.  
  11. ' PART 3: Write the file back.
  12. If MsgBox("Write data back to the file?", vbYesNo) = vbYes Then
  13. Put #FileNo, 1, Buffer() ' Write the data back to the file.
  14. End If
  15. End Sub
  16.  
  17.  
  18.  
  19. Private Sub command2_click()
  20.  
  21. Dim mHandle
  22. Open "a:\bonding.bin" For Binary Access Read Write Lock Write As mHandle
  23. ReWrite_Open_File mHandle
  24.  
  25. End Sub
this code give error bad file name or number.Why it give such error.when i put the break point and find out where the error the occur it occur in the line 1.
Jul 18 '07 #1
1 1227
Killer42
8,435 Expert 8TB
Looks like you have zero in variable mHandle.

When you issue the Open statement, you have to supply the number of the "handle" to associate with that file. Generally, you should use the FreeFile function to get the next available number. For example...
Expand|Select|Wrap|Line Numbers
  1. Private Sub command2_click()
  2.   Dim mHandle
  3.   mHandle = FreeFile
  4.   Open "a:\bonding.bin" For Binary Access Read Write Lock Write As mHandle
  5.   ReWrite_Open_File mHandle
  6. End Sub
Caution: Once again this is merely demonstrating specific parts of the code. There are real problems with this code. For example, we are throwing away the value of mHandle when we exit the Click routine, but the file is still open. Big mistake!
Jul 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
9
by: Hans-Joachim Widmaier | last post by:
Hi all. Handling files is an extremely frequent task in programming, so most programming languages have an abstraction of the basic files offered by the underlying operating system. This is...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
6
by: Paul | last post by:
Hi there, When adding a "File Field" HTML control to an aspx page to facilitate file uploading, the following occurs: 1. You select a file that is larger than the allowed size limit. 2. Once...
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
9
by: chat | last post by:
Hi, every body. I have 3 files like this: -------------------------------------------------------- file name : header.h #ifndef TEST_H #define TEST_H int a=1; double b=0.5;
22
by: Dale Pennington | last post by:
I find myself in the odd situation of trying to determine the name of a file that has been opened somewhere else with an fopen call, so all I have is the FILE * from that fopen call. I perused my...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.