Results 1 to 4 of 4

Thread: Couple of questions on text files.

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2002
    Posts
    86

    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.

  2. #2
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    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

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    1)

    VB Code:
    1. '' while you're outputting lines, record how many lines you're outputting.
    2.     '' so put this in a counter called nLines, and then :
    3.     ''
    4.    
    5.     Dim nLines As Long: nLines = 5 '' lets pretend 5 lines
    6.     Open "c:\a.txt" For Binary As #1
    7.         Dim strBuff As String: strBuff = Space(LOF(1))
    8.     Close #1
    9.     Open "c:\a.txt" For Output As #1
    10.         Print #1, strBuff & vbCrLf & nLines;
    11.     Close #1
    12.    
    13.    
    14.     '' or if you haven't been recording :
    15.     ''
    16.     Open "c:\a.txt" For Binary As #1
    17.         Dim strBuff As String: strBuff = Space(LOF(1))
    18.     Close #1
    19.     Open "c:\a.txt" For Output As #1
    20.         Print #1, strBuff & vbCrLf & UBound(Split(strBuff, vbCrLf));
    21.     Close #1
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    2)

    VB Code:
    1. Left(FirstName,25)

    3)
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim x As Date
    3.     x = #1/13/2002#
    4.    
    5.     MsgBox Format(x, "dd/mm/yy")
    6.     MsgBox Format(x, "dd/mm/yyyy")
    7.    
    8. 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
  •  



Click Here to Expand Forum to Full Width