Description
The LastError
method lets you obtain the last error string that was generated by a method of the Files
, Objects
or Regions
object.
Declaration
ProgObj.LastError()
ProgObj | An expression, variable or parameter that specifies a reference to one of the objects listed in the Applies To section | |||
Result | String |
Applies To
The method is applied to the following objects:
Result Value
The text of the last error generated by a method of the Files
, Objects
or Regions
object.
Remarks
For instance, if the file whose name was passed to the Add
method cannot be found, LastError
will hold an error string about that. This string will not be replaced until another method of the collection object returns an error value -- methods that generate no error do not change LastError
. For example, if the Compare
method returns False, this doesn't mean erroneous behavior because TestComplete does not know which comparison result (True or False) is the expected one. That is why TestComplete does not raise any error unless this method failed to compare the needed values for some reason.
Example
The following example demonstrates how to add a file to the Stores | Files collection using the methods of the Files
object. This example verifies whether the desired file is already in the Files collection, and if it is not there, adds the file to it.
JavaScript, JScript
function StoreFile()
{
var FileName = "C:\\MyFile.txt";
var StoredItemName = "MyFile";
// Verify that StoredItemName is not taken
if (Files.Contains(StoredItemName))
{
Log.Message ("The Files collection already contains this file.");
return;
}
// Add the file to the Files collection
if (Files.Add(FileName, StoredItemName))
Log.Message("The file has been successfully saved in Stores.");
else
Log.Message (Files.LastError);
}
Python
def StoreFile():
FileName = "C:\\MyFile.txt"
StoredItemName = "MyFile"
# Verify that StoredItemName is not taken
if Files.Contains(StoredItemName):
Log.Message ("The Files collection already contains this file.");
return
# Add the file to the Files collection
if Files.Add(FileName, StoredItemName):
Log.Message("The file has been successfully saved in Stores.")
else:
Log.Message (Files.LastError)
VBScript
Sub StoreFile
Dim FileName, StoredItemName
FileName = "C:\MyFile.txt"
StoredItemName = "MyFile"
' Verify that StoredItemName is not taken
If Files.Contains(StoredItemName) Then
Log.Message ("The Files collection already contains this file.")
End If
' Add the file to the Files collection
If Files.Add(FileName, StoredItemName) Then
Log.Message ("The file has been successfully saved in Stores.")
Else
Log.Message (Files.LastError)
End If
End Sub
DelphiScript
procedure StoreFile;
var FileName, StoredItemName;
begin
FileName := 'C:\MyFile.txt';
StoredItemName := 'MyFile';
// Verify that StoredItemName is not taken
if Files.Contains(StoredItemName) then
Log.Message ('The Files collection already contains this file.');
// Add the file to the Files collection
if Files.Add(FileName, StoredItemName) then
Log.Message('The file has been successfully saved in Stores.')
else
Log.Message (Files.LastError);
end;
C++Script, C#Script
function StoreFile()
{
var FileName = "C:\\MyFile.txt";
var StoredItemName = "MyFile";
// Verify that StoredItemName is not taken
if (Files["Contains"](StoredItemName))
{
Log["Message"]("The Files collection already contains this file");
return;
}
// Add the file to the Files collection
if (Files["Add"](FileName, StoredItemName))
Log["Message"]("The file has been successfully saved in Stores.");
else
Log["Message"](Files["LastError"]);
}
See Also
Add Method
Remove Method
FileNameByName Method
NameByFileName Method
Files.Compare Method
Regions.Compare Method
Objects.Compare Method