Solved

Reading a file from VBscript or visual basic 6.0

Posted on 2004-09-23
4
147 Views
Last Modified: 2013-11-25
Hello, i need to deal with a text file from VBScript or visual basic 6.0 and in the process replace a word like blue for yellow, where can i find an example of it?
0
Comment
Question by:emont
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 60 total points
ID: 12134934
Here is a VB6 solution:

Option Explicit

Private Sub Command1_Click()
    replaceInFile "C:\someFile.txt", "blue", "yellow"
End Sub

Private Sub replaceInFile(ByVal fileName As String, ByVal oldString As String, ByVal newString As String)
    Dim ff As Integer
    Dim entireFile As String
   
    If Dir(fileName) <> "" Then
        ff = FreeFile
        Open fileName For Binary Access Read As #ff
        entireFile = Input(LOF(ff), ff)
        Close #ff
   
        entireFile = Replace(entireFile, oldString, newString)
   
        ff = FreeFile
        Open fileName For Binary Access Write As #ff
        Put #ff, , entireFile
        Close #ff
    Else
        MsgBox fileName, vbCritical, "File not found"
    End If
End Sub
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now