Results 1 to 2 of 2

Thread: How do I Save a .prn file in VB

  1. #1
    Guest
    I am trying to create a file that can be imported into Simply Accounting. This file will have all the account numbers and name for a chart of accounts.

    I have fiqured out that if I create the file in Excel and then save it as a formatted text space delimited .prn file that I can then import it into Simply Accounting.

    If I just create a text file with everything else the same. Ie. the file will look visually identical to the .prn file, it won't import into Simply Accounting.

    Saving as a .prn in Excell must attach something to the file in the background that Simply Accounting needs to import properly.

    I need to create the file in VB, ie. write to a file on a disk. I somehow need to get VB to save in the .prn format.

    I have tried all option using:
    SaveAs filename:="a:\fbc_Smplychart.prn", FileFormat:=2


    But I just can't get the format.

    Any Ideas?

    [email protected]

    Cheers,

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    In VB (actually dating back to the good old days of QBasic and GW-BASIC), there are two different statements you can use to create text files: WRITE or PRINT.

    When you use WRITE, VB will create a COMMA-DELIMITED file; whereas when you use PRINT, no special formatting (other than what you specify) will take place. I suspect you want to create the file using PRINT.

    I'll give you two examples, both assuming the user enters "101" and "Account #1" for the first account, and "102" and "Account #2" for the second:

    EXAMPLE 1
    Code:
    'Creating a text file using WRITE
    Dim intFileNbr  As Integer
    Dim strAcctNo   As String
    Dim strAcctName As String
    
    intFileNbr = FreeFile
    Open "a:\fbc_Smplychart.prn" For Output As #intFileNbr
    strAcctNo = InputBox _
        ("Enter an account number (leave blank to quit):", _
          "Account Number")
    Do Until strAcctNo = ""
        strAcctName = InputBox _
               ("Enter the account name:", "Account Name")
        Write #intFileNbr, strAcctNo, strAcctName
        strAcctNo = InputBox _
            ("Enter an account number (leave blank to quit):", _
              "Account Number")
    Loop
    Close #intFileNbr
    The above will produce the following (not what you want):
    "101","Account #1"
    "102","Account #2"

    EXAMPLE 2
    Code:
    'Creating a text file using PRINT
    Dim intFileNbr  As Integer
    Dim strAcctNo   As String
    Dim strAcctName As String
    
    intFileNbr = FreeFile
    Open "a:\fbc_Smplychart.prn" For Output As #intFileNbr
    strAcctNo = InputBox _
        ("Enter an account number (leave blank to quit):", _
          "Account Number")
    Do Until strAcctNo = ""
        strAcctName = InputBox _
               ("Enter the account name:", "Account Name")
        ' Watch your syntax here: comma after the file #, 
        ' but separate each item with a semicolon ...
        Print #intFileNbr, strAcctNo; strAcctName
        strAcctNo = InputBox _
            ("Enter an account number (leave blank to quit):", _
              "Account Number")
    Loop
    Close #intFileNbr
    The above will produce the following (possibly what you want?):
    101Account #1
    102Account #2

    If you want a space in between each item, you can change your Print statement to:
    Print #intFileNbr, strAcctNo; Space$(1); strAcctName

    I hope this helps. If not, post again and we'll give 'er another shot.

    "It's cold gin time again ..."

    Check out my website here.

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