Editing external Notepad log file using VB application

Posted on 2003-03-13
Medium Priority
Last Modified: 2008-03-04
I have a VB6 application which basically installs various applications on a machine. These applications are novell delivered and the VB app pulls them in from an *.ini file. What i would like to do is have the program write into an existing log.txt file the names of the applications it installs.

I have it already writing the information into the registry using a module, but i am unsure how to get VB to write any information into an external notepad file.

Thanks everyone in advance
Question by:JasonRegan
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 14

Accepted Solution

aelatik earned 336 total points
ID: 8126497
Private Sub Form_Load()
    Const ForAppending = 8
    Const Create = True
    Dim MyFileSystemObject
    Dim MyLogFile
    Dim MyLogFileName
    Dim MyLogString
    MyLogFileName = "c:\filename.txt"
    Set MyFileSystemObject = CreateObject("Scripting.FileSystemObject")
    Set MyLogFile = MyFileSystemObject.OpenTextFile(MyLogFileName, ForAppending, Create)

        MyLogString = "This is the text"
        MyLogFile.write MyLogString
        MyLogFile.Writeline ""

    Set MyLogFile = Nothing
    Set MyFileSystemObject = Nothing

End Sub
LVL 43

Assisted Solution

TimCottee earned 332 total points
ID: 8126537
Hi JasonRegan,

This is actually very simple:

Dim intFHandle As Integer
intFHandle = FreeFile()
Open "C:\mylogfiles\Installation.txt" For Output As #intFHandle
Print #intFHandle,"Application Installation : MyNewApplication"
Close #intFHandle

And that is all there is to it. This simply outputs whatever you put in the second parameter of the Print # statement to the file specified in the Open statement.


Brainbench MVP for Visual Basic

Experts-Exchange Advisory Board Member
LVL 43

Expert Comment

ID: 8126551
Just a comment, don't use the filesystemobject unless you really have to! It requires IE to be installed on the client and the scripting runtime enabled (it may be disabled by a system administrator). Also it may add significant overhead to deployment. VB has native file functions as shown that can achieve almost everything you would need to do. The filesystemobject is available because it is necessary for VBScript which doesn't have the native file functions, I would caution strongly against its use in VB proper unless absolutely necessary.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 8128429
Here Here!

Someone else that hate the File Sucking Object. YES!

Assisted Solution

Diveblue earned 332 total points
ID: 8130082
Just a note - Tim's code is correct, but opening the file for output each time will overwrite previous lines. You may want to consider using the following, which will append to the end of the file.

Open "C:\mylogfiles\Installation.txt" For Append As #intFHandle

Expert Comment

ID: 8900175
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
LVL 49

Expert Comment

ID: 9692795
Moderator, my recommended disposition is:

    Split points between: aelatik and TimCottee and Diveblue

DanRollins -- EE database cleanup volunteer

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 17 hours left to enroll

762 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