Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Reading a file from VBscript or visual basic 6.0

Posted on 2004-09-23
4
Medium Priority
?
160 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 86

Accepted Solution

by:
Mike Tomlinson earned 240 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

926 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