' The following is an example of the script viewer control ' that allows you to view the test. ' Using Microsoft Visual Basic, create a new ActiveX Control project. ' Choose Project > References, and select the OTA COM 8.0 Type Library reference. ' For this example, you must also select a reference to the ' Microsoft Scripting Runtime, though you may not need it for your production code. ' Add a text box to the user control. The script contents are displayed inside the box. ' Add a Command button named cmdSave. The button is used to save changes to the script.
Private td AsNew TDAPIOLELib.TDConnection Private tfact As TDAPIOLELib.TestFactory Private theTest As TDAPIOLELib.Test Private LocalScriptPath AsString Private ExtStorage As TDAPIOLELib.ExtendedStorage
' '******************************************************************* PublicSub Init(mytd AsVariant) ' Initialization method, Quality Center will call this ' method and pass an TDConnection class object. Set td = mytd
EndSub
PublicSub ShowTest(TestKey AsLong) ' ShowTest(TestKey As Long) always displays the most recent ' checked-in version of the test. ' From Quality Center version 10.0 and later, Quality Center ' calls ShowTestEx if it is implemented.
' This implementation of ShowTest gets the path for the specified test ' using its key, reads the script file (Batch.bat) from this location, ' and displays it in the text box. ' Dim mydata AsString
OnErrorGoTo ShowTestErr
'Get the test Set tfact = td.TestFactory Set theTest = tfact.Item(TestKey)
'Get a local copy of the script 'In this example, the script is "batch.bat" Set ExtStorage = theTest.ExtendedStorage LocalScriptPath = ExtStorage.Load("-r batch.bat", True)
'Add the file name to the path returned from Load 'so it directly refers to the file. LocalScriptPath = LocalScriptPath & "\batch.bat"
'Open the script Set oFileSys = _ CreateObject("Scripting.FileSystemObject") Set ScriptFile = _ oFileSys.OpenTextFile(LocalScriptPath, _ ForReading, False)
'Get the contents of the file into a string variable IfNot ScriptFile.AtEndOfStream Then _ mydata = ScriptFile.ReadLine DoWhile ScriptFile.AtEndOfStream <> True 'List1.AddItem ScriptFile.ReadLine mydata = mydata & vbCrLf & ScriptFile.ReadLine Loop ScriptFile.Close
' Load the script text into the text box. ' Note that the text box must have the Multi-line ' attribute enabled. Text1.Text = mydata Text1.Enabled = False
PublicSub ShowTestEx(theTest As TDAPIOLELib.Test) ' Quality Center will call the ShowTestEx method and pass ' a reference to the test object. The appropriate version ' of the test is displayed.
' This implementation of ShowTestEx gets the path for the specified test ' using its key,reads the script file (Batch.bat) from this location, ' and displays it in the text box. ' Dim mydata AsString
OnErrorGoTo ShowTestErr
'Get a local copy of the script 'In this example, the script is "batch.bat" Set ExtStorage = theTest.ExtendedStorage LocalScriptPath = ExtStorage.Load("-r batch.bat", True)
'Add the file name to the path returned from Load 'so it directly refers to the file. LocalScriptPath = LocalScriptPath & "\batch.bat"
'Open the script Set oFileSys = _ CreateObject("Scripting.FileSystemObject") Set ScriptFile = _ oFileSys.OpenTextFile(LocalScriptPath, _ ForReading, False)
'Get the contents of the file into a string variable IfNot ScriptFile.AtEndOfStream Then _ mydata = ScriptFile.ReadLine DoWhile ScriptFile.AtEndOfStream <> True 'List1.AddItem ScriptFile.ReadLine mydata = mydata & vbCrLf & ScriptFile.ReadLine Loop ScriptFile.Close
' Load the script text into the text box. ' Note that the text box must have the Multi-line ' attribute enabled. Text1.Text = mydata Text1.Enabled = False