|
-
Nov 19th, 2002, 04:59 AM
#1
Thread Starter
Lively Member
Couple of questions on text files.
I am inserting a number of lines into a text file with information in them.
1) After I have all the lines inserted. I want to go back to the first line and enter the number of lines inserted.
2) In each line I insert a person's name e.g. Left(FirstName,25).
But when the data is retrieved from the text file it contains " ".
e.g. "Tom ". I want to remove the "".
3) I also insert the current date but it is being logged in dd/mm/yy. I want it to be dd/mm/yyyy.
Anyone any ideas?
Thanks in advance.
-
Nov 19th, 2002, 05:10 AM
#2
Frenzied Member
For the date format it to desired format
like Format(Date,"dd/mm/yyyy")
Be aware if you read it back in into a date variable it can be misread if the settings for date are different.
To go back to first don't know if possible if you close first and reopen it for output it will be overwritten.
Can't you know how much inserts will be done before you start inserting lines into it ??
To remove the space fill the string with Trim(readline)
Code:
If Question = Incomplete Then
AnswerNextOne
Else
ReplyIfKnown
End If
cu Swatty
-
Nov 19th, 2002, 05:11 AM
#3
Retired VBF Adm1nistrator
1)
VB Code:
'' while you're outputting lines, record how many lines you're outputting.
'' so put this in a counter called nLines, and then :
''
Dim nLines As Long: nLines = 5 '' lets pretend 5 lines
Open "c:\a.txt" For Binary As #1
Dim strBuff As String: strBuff = Space(LOF(1))
Close #1
Open "c:\a.txt" For Output As #1
Print #1, strBuff & vbCrLf & nLines;
Close #1
'' or if you haven't been recording :
''
Open "c:\a.txt" For Binary As #1
Dim strBuff As String: strBuff = Space(LOF(1))
Close #1
Open "c:\a.txt" For Output As #1
Print #1, strBuff & vbCrLf & UBound(Split(strBuff, vbCrLf));
Close #1
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 19th, 2002, 05:14 AM
#4
Retired VBF Adm1nistrator
2)
3)
VB Code:
Private Sub Form_Load()
Dim x As Date
x = #1/13/2002#
MsgBox Format(x, "dd/mm/yy")
MsgBox Format(x, "dd/mm/yyyy")
End Sub
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|