Home > Software engineering >  VB log can't write complete
VB log can't write complete

Time:09-17

Each prawn,

I in vb to write a small tool, run the following code is used to implement the records into *. The log file, but found that the program runs very fast, a lot of entries without saving, especially when program debugging error, a operation record can only be written on the part of: could you tell me how to handle this,
The output of the log file:

Module1:
 '* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * log records * * * * * * * * * * * * * * * * * Start * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
The Public Function openLogfile ()
Dim F As String
'the nStr=Format (Now, "yyyy - mm - dd hh: mm: ss") & amp; NStr
F=App. Path & amp; "\ log " & amp; Format (Now, "yyyymmddhhmmss") & amp; "Log", "
'if you want to save the file to the same folder as your exe, on the other to F=App. The Path & amp; "\ myprog log"
H=FreeFile
On the Error Resume Next
The Open F For Append As # H
End the Function
The Public Function MyLog (nStr As String)
Print # H, the Format (Now, "yyyy - mm - dd hh: mm: ss")
Print # H, nStr
End the Function
The Public Function logfileClose ()
Close # H
The Set H=Nothing
Set the log=Nothing 'release logging variables
End the Function

'* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * log records * * * * * * * * * * * * * * * * * End * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *


Program invocation:
 log="' TrayNofound query tray corresponding class conditions, and show the sninfo (1) in the Sql=" & amp; SQL 
Call MD2. MyLog (log) 'writing log

CodePudding user response:

Your code above line 18 (dislocation line number, but 18 told me that line a little "to be neatly") would be is not an error?


Visible your code isn't correct, I don't understand your line 13, 14 lines how can "the data is written to the file,"

In your opening the "logging" module, write down this sentence, and then modify the code, can "fully compile operation" to say again!!!!!!
Option Explicit

CodePudding user response:

reference 1st floor Chen8013 response:
your code above line 18 (dislocation line number, but 18 told me that line a little "to be neatly") would be is not an error?


Visible your code isn't correct, I don't understand your line 13, 14 lines how can "the data is written to the file,"

In your opening the "logging" module, write down this sentence, and then modify the code, can "fully compile operation" to say again!!!!!!
Option Explicit



Excuse me, may be I didn't post code complete,
On the top of the module1, have stated option explicit, and there are public log and H,

CodePudding user response:

"Write file and write the disk are two concepts,

Write files in the file is only to write data into the memory buffer, unless, speaking, reading and writing content across the buffer of the disk area, only partly written to disk,

Really written to disk, which is triggered by Close operation,

Suggest you scrap the three-step method and open every time to write the log is executed, write and closed operation, otherwise, in the event of a failure, the Close may not perform,

CodePudding user response:

refer to the second floor lisaksq response:
Quote: refer to 1st floor Chen8013 response:

Your code above line 18 (dislocation line number, but 18 told me that line a little "to be neatly") would be is not an error?


Visible your code isn't correct, I don't understand your line 13, 14 lines how can "the data is written to the file,"

In your opening the "logging" module, write down this sentence, and then modify the code, can "fully compile operation" to say again!!!!!!
Option Explicit



Excuse me, may be I didn't post code complete,
On the top of the module1, have stated option explicit, and the public the log and H,

Even so...
But:
1. You are in several of the process (functions) in a module used in the "file number",
The variable should be obviously Private "special variables", rather than a statement to Public!
(you promise not to use the "H" elsewhere this variable? If it does not, the problem is not big; But "dedicated" is the best Private)
2. "file number" is an Integer (of course is not to say that can only be an Integer, with Long or Byte is not "absolutely wrong"),
How can the Set H="Nothing"???????
For this is "object type variable, you don't an error code in there?
So can also infer your "H" is the Variant type variable, rather than "value type",


3. This is like the second floor, "write files" statement, at ordinary times is written on the disk in the buffer,
In most cases do not brush to "close the file" disk (of course not "absolute", is also likely to have closed, the system also brush buffer),
If writing no brush to disk in a timely manner, in suddenly loses power, the program crashes, process forcibly cases, such as the end
Is likely to be "written" content and no effect (no brush to disk), so there is the problem of "the record is not complete",

CodePudding user response:

reference of123 reply: 3/f
"written document" and write the disk is two concepts,

Write files in the file is only to write data into the memory buffer, unless, speaking, reading and writing content across the buffer of the disk area, only partly written to disk,

Really written to disk, which is triggered by Close operation,

Suggest you scrap the three-step method and open every time to write the log is executed, write and closed operation, otherwise, in the event of a failure, the Close may not perform,

I originally is also according to the integral program, but the log file is bigger, open and close all need a period of time, the program runs caton, so we changed to three sections,

CodePudding user response:

reference 4 floor Chen8013 response:
Quote: refer to the second floor lisaksq response:

Quote: refer to 1st floor Chen8013 response:

Your code above line 18 (dislocation line number, but 18 told me that line a little "to be neatly") would be is not an error?
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related