Save Method

Applies to TestComplete 14.92, last modified on September 16, 2021

Description

Use the Save method to save options to the file for which the FileSection object was created. This is the file you specified in the XML, INI or Binary method of the Storages object. If the file does not exist, the Save method creates it. If you do not call the Save or SaveAs method of the FileSection object, all the changes will be lost.

Declaration

FileSectionObj.Save()

FileSectionObj An expression, variable or parameter that specifies a reference to a FileSection object
Result None

Applies To

The method is applied to the following object:

Result Value

None.

Example

The code below obtains a binary file, makes some changes to the options stored in the file and then saves the file under the same name.

JavaScript, JScript

function FileSectionExample()
{
  // Obtains the file to get access to
  var sFile = Storages.Binary("C:\\Work\\OptionsFile.txt");
  // Obtains the total number of options stored in the file
  var OptNum = sFile.OptionCount;
  
  // Iterates through the options
  for (var i = 0; i < OptNum; i++)
    // Makes some changes to the current option
    sFile.SetOptionByIndex(i, "...");
  
  // Saves the file
  sFile.Save();
   
}

Python

def FileSectionExample():
  # Obtains the file to get access to
  sFile = Storages.Binary("C:\\Work\\OptionsFile.txt")
  # Obtains the total number of options stored in the file
  OptNum = sFile.OptionCount
  # Iterates through the options
  for i in range(0, OptNum):
    # Makes some changes to the current option
    sFile.SetOptionByIndex[i, "..."]
  # Saves the file 
  sFile.Save()

VBScript

Sub FileSectionExample

  ' Obtains the file to get access to
  Set sFile = Storages.Binary("C:\Work\OptionsFile.txt")
  ' Obtains the total number of options stored in the file
  OptNum = sFile.OptionCount
  
  ' Iterates through the options
  For i = 0 to (OptNum - 1)
    ' Makes some changes to the current option
    Call sFile.SetOptionByIndex(i, "...")
  Next
  
  ' Saves the file
  sFile.Save
   
End Sub

DelphiScript

function FileSectionExample;
var sFile, OptNum, i;
begin

  // Obtains the file to get access to
  sFile := Storages.Binary('C:\Work\OptionsFile.txt');
  // Obtains the total number of options stored in the file
  OptNum := sFile.OptionCount;
  
  // Iterates through the options
  for i := 0 to (OptNum - 1) do
    // Makes some changes to the current option
    sFile.SetOptionByIndex(i, '...');
  
  // Saves the file
  sFile.Save();
   
end;

C++Script, C#Script

function FileSectionExample()
{
  // Obtains the file to get access to
  var sFile = Storages["Binary"]( "C:\\Work\\OptionsFile.txt" );
  // Obtains the total number of options stored in the file
  var OptNum = sFile["OptionCount"];
  
  // Iterates through the options
  for (var i = 0; i < OptNum; i++)
    // Makes some changes to the current option
    sFile["SetOptionByIndex"]( i, "..." );
  
  // Saves the file
  sFile["Save"]();
   
}

See Also

FileSection.SaveAs
Storages Object
Storages.Binary
Storages.INI
Storages.XML

Highlight search results