+ Reply to Thread
Results 1 to 2 of 2

droping leading zeros when writing to a file

  1. #1
    colin.marker@gmail.com
    Guest

    droping leading zeros when writing to a file

    My problem is that VBA is writing the numbers to a file PATH but it
    drops the leading zeros. I already tried to make them strings but if I
    do that then it adds parenthesis to the "string" which I dont want. I
    dont understand why it is not writing EXACTLY what I am telling it to
    output to file. Please help, thanks.

    Colin Marker

    Code ->

    intFile = FreeFile
    Open PATH For Append As #intFile
    colIndex = 1
    rwIndex = 1

    Do Until Cells(rwIndex, colIndex) = ""
    Write #intFile, 0.53, 5.24, 0.15, -0.58, -0.862
    rwIndex = rwIndex + 1
    Loop
    Close #intFile


  2. #2
    Gareth
    Guest

    Re: droping leading zeros when writing to a file

    Hi Colin,

    Use Print rather than Write. This will work as you wish:

    Print #intFile, 0.53, 5.24, 0.15, -0.58, -0.862

    In addition, I assume you're taking this data from your worksheet. Don't
    forget you can always use Format to easily modify the format of the
    numbers.

    rwIndex = 1
    colIndex = 1
    Do Until Cells(rwIndex, colIndex) = ""
    Do Until Cells(rwIndex, colIndex) = ""
    Print #intFile, Format(Cells(rwIndex, colIndex),"00.00#")
    colIndex = colIndex + 1
    Loop
    colIndex = 1
    rwIndex = rwIndex + 1
    Loop

    HTH,
    Gareth

    colin.marker@gmail.com wrote:
    > My problem is that VBA is writing the numbers to a file PATH but it
    > drops the leading zeros. I already tried to make them strings but if I
    > do that then it adds parenthesis to the "string" which I dont want. I
    > dont understand why it is not writing EXACTLY what I am telling it to
    > output to file. Please help, thanks.
    >
    > Colin Marker
    >
    > Code ->
    >
    > intFile = FreeFile
    > Open PATH For Append As #intFile
    > colIndex = 1
    > rwIndex = 1
    >
    > Do Until Cells(rwIndex, colIndex) = ""
    > Write #intFile, 0.53, 5.24, 0.15, -0.58, -0.862
    > rwIndex = rwIndex + 1
    > Loop
    > Close #intFile
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1