Intellipro     

AutomatingTest Automation                  Home Automation Articles Downloads QTP Gotchas Links Books Contact About Site Map

File Function - Read String

This function reads the entire contents of a file into a string.

If you find an error, or have a suggestion for improvement, Email me and I'll fix it.

Download it Here (right-click and then save target as).

(NOTE - you can just cut & paste from below, but the formatting will have multiple spaces instead of tabs).

'=========================================================================

Function zFile_ReadString(sFileName)

'This function reads the entire contents of a file into a string

'An empty string is returned if the file is empty or if the file does not exist

'Example of Usage:
'    sFile = zFile_ReadString("c:\file.txt")

    Print "zFile_ReadString: " & sFileName

    Dim oFso, oFile
    Const ForReading = 1, ForWriting = 2, ForAppending = 8

    Set oFso = CreateObject("Scripting.FileSystemObject")

    If oFso.FileExists(sFileName) Then

        'Open the file for reading
        Set oFile = oFso.openTextFile(sFileName, ForReading)

        'Read ALL from the file and return it from the function
        zFile_ReadString = oFile.ReadAll

        'Close the file
        oFile.Close

        Set oFile = Nothing

    Else
        Print "File_ReadString - File NOT found: " & sFileName

        'Return nothing from the function
        zFile_ReadString = ""

    End If

    Set oFso = Nothing

End Function

'=========================================================================

Copyright © 2011 Intellipro Services Ltd. All rights reserved                      Home About Privacy Policy Terms of use Contact Site Map






































































advanced advice agile answers application articles aut automated automating automation basics beginners browser button checkbox child childobjects click close code coding combo combobox consultant consultancy convention count createobject database delete descriptive download downloads dp edit editbox element enhancements error examples faq faqs file files filesystemobject fixes folder folders forum framework frameworks function functions generation generator getobject getroproperty gotchas group guide guru harness hewlett hp inputbox insert intellipro interview language library libraries link list listbox manifesto manual master name naming navigate object or packard page ping pro problem procedure procedures professional programming qtp query queries question questions quick quicktest radio refresh repository ross row rows samples script scripts scrum select server software specific sprint sql step stored strategy structure sub subroutine suite sync tables test testing text textbox title tool tools tsl tutorial update updates url vbscript web webedit webpage webradiogroup weblist whittaker wscript