?
Solved

Vb to generate txt file report

Posted on 2004-11-29
3
Medium Priority
?
148 Views
Last Modified: 2010-05-02
I have a text file contains:

a b c d
e f g h
j k e j

How do I can create a VB application to read this text file and generate a report?...and from the report itself i also can see the total listing in the text file....

thanks
0
Comment
Question by:operation1612
3 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 12703052
What should be in the report besides the contents of the text file?
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 200 total points
ID: 12703220
Standard flat file Read and write routines:

Read:
    Dim intFileHandle As Integer
    Dim strRETP As String
    intFileHandle = FreeFile
    Open "path to file" For Input As #intFileHandle
    Do While Not EOF(intFileHandle)
        Line Input #intFileHandle, strRETP
        MsgBox strRETP
    Loop
    Close #intFileHandle

Write (creates a new file overwriting any existing file):
    Dim intFileHandle As Integer
    Dim strRETP As String
    strRETP = "Hi There"
    intFileHandle = FreeFile
    Open "path to file" For Output As #intFileHandle
    Print #intFileHandle, "---------------------------"
    Print #intFileHandle, strRETP
    Print #intFileHandle, "---------------------------"
    Close #intFileHandle

Write (appends data to an existing file):
    Dim intFileHandle As Integer
    Dim strRETP As String
    strRETP = "Hi There"
    intFileHandle = FreeFile
    Open "path to file" For Append As #intFileHandle
    Print #intFileHandle, "---------------------------"
    Print #intFileHandle, strRETP
    Print #intFileHandle, "---------------------------"
    Close #intFileHandle


Some remarks:
1) You should use "Write" instead of "Print" to output comma separated values. e.g.:
Dim iOne as integer, iTwo as integer, iThree as String
iOne=1
iTwo=12
iThree="A"
...
Write #intFileHandle, iOne,iTwo,iThree
...
Gives this output:
1,12,A

etc.

2) You should then use "Input" not "Line Input" to read the comma separated values:
Dim xOne as integer, xTwo as integer, xThree as String
...
Input #intFileHandle, xOne,xTwo,xThree
...

This reads each separated value into the specified variables...
0
 

Author Comment

by:operation1612
ID: 12712770
tq
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question