Define Environment Variables
Source code
'This example sends parameters to a test by defining environment variables before running the test.
'It also lists the user and operating system from each test run in the test's description.
'There is no unsaved test currently open in UFT One.
'For more information, see the example for the Test.SaveAs method.
'When UFT One opens, it loads the add-ins required for the test.
'For more information, see the example for the Test.GetAssociatedAddins method.

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtOptions 'As QuickTest.RunResultsOptions ' Declare the Run Results Options object variable
Dim strOS
Dim strUserName

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start UFT One
qtApp.Visible = True ' Make the UFT One application visible

' Open the test
qtApp.Open "C:\Tests\Test1", False ' Open a test named "Test1"

' Set some environment variables
qtApp.Test.Environment.Value("Root") = "C:\" ' Set the "Root" environment variable. Note: 'Value' is a default property and can be omitted.
qtApp.Test.Environment.Value("Password") = "not4you" ' Set the "Password" environment variable
qtApp.Test.Environment.Value("Days") = 14 ' Set the "Days" environment variable

' Run the test
Set qtOptions = CreateObject("QuickTest.RunResultsOptions") ' Create a Results Option object
qtOptions.ResultsLocation = "<TempLocation>" ' Set the Results location to temporary location
qtApp.Test.Run qtOptions, True ' Run the test and wait for it to finish before continuing the automation script

' Concatenate data stored in the environment to the description
strOS = qtApp.Test.Environment.Value("OS") ' Return the "OS" environment variable
strUserName = qtApp.Test.Environment.Value("UserName") ' Return the "UserName" environment variable
qtApp.Test.Description = qtApp.Test.Description & vbNewLine & _
       "Tested on: " & Now & vbNewLine & _
       "Platform: " & strOS & vbNewLine & _
       "By user: " & strUserName & vbNewLine & _
       "-------------------------" & vbNewLine ' Add the current time, OS, and user name to the test's description

qtApp.Test.Save ' Save the test

qtApp.Quit ' Exit UFT One
Set qtOptions = Nothing ' Release the Run Results Options object
Set qtApp = Nothing ' Release the Application object