Created On: 04 April 2011 SilkTest Workbench contains no native methods for reading and writing to text or ini files. Attached to this resolution is a compiled dll for a fileIO class library that will allow you to read and write to text files and ini files. These are the equivalent of the SilkTest Classic Filexxxx and IniFilexxxx methods. In the case of the Filexxxx methods they have been compressed to two methods only - readLine and writeLine - as file open and file close is done automatically when the read and write methods are called. The inifile methods are a wrapper around the Read/Write PrivateProfile functions supplied with pre- dotNet versions of Visual Studio. Microsoft would prefer users of Visual Studio to move to storing information directly in the registry or as an xml file but there are many tens of thousands of applications that still use the much simpler inifile structure. Although the examples below show hard-coded strings you can just as easily use variables to simplify your code. Copy fileIO.dll to a folder on your hard drive. A suggested place is to create a new folder in your SilkTest installation called ‘Workbench modules’; note that if you uninstall SilkTest this folder will not be deleted. You will need to add a reference to the fileIO.dll in your Workbench project to enable usage of the class libraries. 1. From the Workbench script IDE select the ‘Properties’ tab. 2. Right-click on ‘References’ and select ‘Add Reference’ 3. ‘Browse’ to wherever you have placed filePrint.dll and select it 4. Click ‘Open’ 5. Click ‘Okay’ The class library is now ready for use. The constructors and method calls are broken down in detail below. Text file commands Constructor: Dim [objectname] as New fileIO.fileIO() e.g. Dim fileReadWrite as New fileIO.fileIO() writeLine Method [optional] boolean =writeLine(filename, data, [optional] writetype) where writetype = 'append' or 'new'. The default write method is 'append' but if the file does not exist it will be created. Similarly, if 'new' is called and the file exists then the original file will be overwritten. writeLine can return an optional 'true' or 'false' to indicate success or failure. e.g. to append a line without checking if the action has succeeded or failed and without knowing if the file currently exists: fileReadWrite.writeLine("c:\\temp\\mydata.txt","new data line") readLine Method readLine(filename, [optional] startpoint) where startpoint = -1 to start again from the top of the file 0 to continue with the next line any integer to read a specific line. The startpoint default is zero. readLine will return 'eof' as data for end of file or for an invalid line number. It will also return 'file not found' as data if it fails to open or locate the specified file. e.g. to force a read to start again from the top of the file: data = fileReadWrite.readLine("c:\\temp\\mydata.txt",-1); INI file commands The ini file methods stick rigidly to the old Read/Write PrivateProfile functions pattern of sectionname, keyname, default value and ini file name. Constructor: Dim [objectname] as New fileIO.Ini() e.g. Dim myIniFile as New fileIO.Ini() Write Methods WriteIniString(sectionname, keyname, string, inifilename) WriteIniInteger(sectionname, keyname, integer, inifilename) e.g. to write string data to the ini file myIniFile.WriteIniString("testsection", "string1", "mydata", "c:\\initest.ini"); Read Methods ReadIniString(sectionname, keyname, default value as string, inifilename) ReadIniInteger(sectionname, keyname, default value as integer, inifilename) e.g. to read an integer with a default return value of -1 myIniFile.ReadIniInteger("testsection", "integer1", -1, "c:\\initest.ini"); Attachments Workbench FileIO.zip Old KB# 33843
↧