473,320 Members | 1,900 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,320 software developers and data experts.

This should never work but it does. Why?

I've just fixed what should be a bug in a simple function to log a message to
a file. The thing is, the original code worked!

Protected Sub LogMessage(ByVal filename As String, ByVal message As
String)
Dim fileNum As Integer

fileNum = FreeFile()
FileSystem.FileOpen(FreeFile(), filename, OpenMode.Append)
FileSystem.PrintLine(fileNum, DateTime.Now.ToString + " - " + message)
FileSystem.FileClose(fileNum)
End Sub

I'm opening the file with one number and then using a different file number
to write the data! Surely the PrintLine and the FileClose should fail. But
the application works and logs mesages to the log file with no problems.

Can anyone explain?

--- Al.
Nov 21 '05 #1
1 1063
"TVR Fan" <TV****@discussions.microsoft.com> wrote in message
news:DD**********************************@microsof t.com...
I've just fixed what should be a bug in a simple function to log a message to a file. The thing is, the original code worked!

Protected Sub LogMessage(ByVal filename As String, ByVal message As
String)
Dim fileNum As Integer

fileNum = FreeFile()
FileSystem.FileOpen(FreeFile(), filename, OpenMode.Append)
FileSystem.PrintLine(fileNum, DateTime.Now.ToString + " - " + message) FileSystem.FileClose(fileNum)
End Sub

I'm opening the file with one number and then using a different file number to write the data! Surely the PrintLine and the FileClose should fail. But
the application works and logs mesages to the log file with no problems.

Can anyone explain?

--- Al.


The original worked because you are using the same file number.

FreeFile returns the next free file number that is not currently in use. The
thing to remember is that until you open a file using that file number, that
file number isn't in use. Therefore the second call to FreeFile returned the
same file number as the first.

However I do agree that it is better style to use:

fileNum = FreeFile()
FileSystem.FileOpen(fileNum ....

hope this helps,

Brian Cryer

www.cryer.co.uk/brian
Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Dave Murray | last post by:
New to Python question, why does this fail? Thanks, Dave ---testcase.py--- import sys, urllib, htmllib def Checkit(URL): try: print "Opening", URL
22
by: Robert Brown | last post by:
suppose I have the following table: CREATE TABLE (int level, color varchar, length int, width int, height int) It has the following rows 1, "RED", 8, 10, 12 2, NULL, NULL, NULL, 20...
2
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: August 28, 2002 Version: 1.15 URL: http://css.nu/faq/ciwas-aFAQ.html...
0
by: Jan Roland Eriksson | last post by:
Archive-name: www/stylesheets/authoring-faq Posting-Frequency: twice a week (Mondays and Thursdays) Last-modified: April 10, 2003 Version: 1.16 URL: http://css.nu/faq/ciwas-aFAQ.html Maintainer:...
24
by: Yang | last post by:
I found a very strange behavior when I write a C# windows application. If I allocate a huge chunk of memory by an array, the memory will never be released by .NET. The problem can be demostrated...
119
by: rhat | last post by:
I heard that beta 2 now makes ASP.NET xhtml compliant. Can anyone shed some light on what this will change and it will break stuff as converting HTML to XHTML pages DO break things. see,...
6
by: Praveen | last post by:
I am pretty much curious about the authenticity of the following article that I recieved from a friend of mine. It is an interview of Bjarne Stroustrup in 1998. I would appreciate some...
83
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face...
9
by: active | last post by:
Can you see why this does not sort the list? It displays OK but is not sorted Thanks for any help
18
by: Jon Slaughter | last post by:
"Instead of just waiting for its time slice to expire, a thread can block each time it initiates a time-consuming activity in another thread until the activity finishes. This is better than...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.