Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excess Characters Put to File (Date Format) 1

Status
Not open for further replies.

jsaliers

Programmer
Jan 23, 2003
129
0
0
US
I am having a stupid problem, and I don't quite know why. I am tryin to write data to a file, and read it back later. The problem is that when I write the formatted date, it prints extra characters to the front of the string, that screw up reading the lines back in. The characters are "space-square-space-square". This is directly followed by my string. I know what line is doing it, but don't understand it. It is the line the first Put line.
Code:
checkDateTime = Format(Now, "mm/dd/yy hh:mm")
checkModel = model
    
'Open hLogFile for Binary Write Access
Temp = "c:\" + model + "\counts\count.txt"
hLogFile = FreeFile
Open Temp For Binary Access Write As hLogFile
    
'Enter Date/Time/Model
[COLOR=red]Put hLogFile5, , checkDateTime & cr[/color]
Put hLogFile5, , checkModel & cr
The other problem is that the format of the date is not working correctly. That is, if the date/time was today at 3:45PM, I want it to be formatted like "12/19/03 15:45", but that doesn't seem to be working either. Any ideas?

Any help is much appreciated. Thank you!

Jon
 
When writing binary data to a file, use a variable that is an array of the Byte data type, instead of a String variable. Strings are assumed to contain characters, and binary data may not be properly stored in String variables.
(VB's Programmer's Guide)

Therefore I suggest following modifications:

Dim checkDateTime As String, Temp As String
Dim hlogFile As Long

Dim a_bytData() As Byte

checkDateTime = Format(Now, "mm/dd/yy hh:mm")
a_bytData = checkDateTime

'Open hLogFile for Binary Write Access
Temp = "C:" & "\counts\counts.txt"
hlogFile = FreeFile
Open TEmp For Binary Access Write As hlogFile

'Enter Date/Time/Model
Put hlogFile, , a_bytData


Use preferrable the & sign to concatenate strings in stead of + (the latter may get you in trouble when the strings contain numbers)



_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Maybe I am going about this wrong. Let me provide some background. I am collecting data serially from a test stand, and printing the counts to file. Each time results come in for a part, the file is read in, to verify that date, shift, or part model has not changed. If it has not, then it reads in the counts, stores them to variable, updates the proper counts, and writes back to the same file. If the date, shift, or part model has changed, the counts file is read in, and appended to a historical count file.

This is what a typical file should look like:

12/19/03 13:55
1
SAN
Total Tested = 135
Total Passed = 132
Total Failed = 3
SANcalctlHIGH 1
SANsetpntLOW 2

The first line is date, second is shift, third is model, 4-6 are total counts, 7 and on are failure modes, and their counts (this file shows that 1 SAN failed high for calctl, and 2 SAN's failed low for setpnt).

The person who started this project used the GET and PUT statements, so to be consistent, I am trying to do the same.

When I write my shift, model, and rest of counts, everything writes to the file correctly. However, when I do the date/time string, it not only formats the string wrong, but also adds characters incorrectly. I have also noticed that if I manually fix the write errors in the file, the reading in does not work correctly. This is a typical statement I used for that:
Code:
hLogFile2 = FreeFile
Temp2 = "c:\" & model & "\counts\count.txt"
Open Temp2 For Binary Access Read As hLogFile2

Get hLogFile2, 1, CountDateTime
Get hLogFile2, 2, CountShift
Get hLogFile2, 3, CountModel

My results while reading in are like this:

CountDate = "12/30/99"
CountShift = "12376"
CountModel = ""

I guess what I am looking for is an opinion: Should I be doing it this way, and debug what I have, or should I do it some other way, and if so what way might that be?

Any help is much appreciated! You guys have helped me so much in the past. Much thanks!

Jon
 
Alright, I have solved a few of my problems. I have gotten rid of the excess characters at the beginning of my date line, and have formatted the date correctly. In addition, I have read in the date line. However, I am still not reading in the shift and model, and I am pretty sure that I know why. The GET statement's second argument is recnumber, which is either the record number or the byte number. I need to read in line by line, not byte by byte. So the first GET statement reads in the first line, the second reads in the second, and so on. Anyone have any ideas on how to read in a file line by line?

Much thanks for your help in advance!!

Jon

PS - rvBasic, thanks much for the tips on byte data type and the "&"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top