11

How to create a new list and save ADD in Visual Basic?

 2 years ago
source link: https://www.codesd.com/item/how-to-create-a-new-list-and-save-add-in-visual-basic.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to create a new list and save ADD in Visual Basic?

advertisements

I have a LIST which contains many record's, I want to extract records based on a condition and if the condition satisfies then I need to add the condition satisfied record into a new list.

Below is the code which I have written till now:

Module Module2
Sub Main()
    Dim td
    td = CreateObject("TDApiOle80.TDConnection")
    td.InitConnectionEx("http://qc10dev/qcbin")
    'Note: For Quality Center, connect by using the URL below:
    'td.InitConnectionEx "http://<servername>:port/qcbin"
    td.ConnectProjectEx("DEFAULT", "GPS_PROGRAM", "PQRST", "XYX@123")
    Dim tsfact 'As TDAPIOLELib.TestSetFactory
    Dim tslist 'As TDAPIOLELib.List
    'Getting Random Test Set ID
    '************************ACCESS ALL THE TEST SETS ********************************************************************        '
    tsfact = td.TestSetFactory
    tslist = tsfact.NewList("")

    '************************GET THE COUNT OF TEST SETS ******************************************************************
    Dim Count_Of_TestSets
    Count_Of_TestSets = tslist.Count
    Console.WriteLine("Count of Test Sets" + Count_Of_TestSets.ToString)

    '************************GET A RANDOM TEST SET INDEX ***************************************************************
    Dim TestSetID As Integer
    Dim TestSetName = Nothing
    Dim SerialNumber As Integer = 0
    Dim AttachmentPresent
    Dim tslist_Having_Attachments = Nothing

    For Each TestSet In tslist

        TestSetID = TestSet.ID
        TestSetName = TestSet.Name
        'Console.WriteLine("TestSet ID::" + TestSetID.ToString() + "Test Set Name" + TestSetName)
        AttachmentPresent = TestSet.HasAttachment()
        If StrComp(AttachmentPresent, "True") = 0 Then
            Console.WriteLine("TestSet ID::" + TestSetID.ToString() + "Test Set Name" + TestSetName)
        End If
    Next

    Console.WriteLine("Logic Completed, Press enter")
    Console.ReadLine()
    tslist = Nothing
    tsfact = Nothing
    td = Nothing
End Sub

End Module

If you go through the above code the base List is tslist.

From this tslist which ever records has satisfied condition StrComp(AttachmentPresent, "True") = 0

has to be added to New list say tslist_attachment.

How can create a new list and add the values?

Please let me know the steps,.

Regards, Srihari


From your description, it seems that you want to have a list of all attachments. You want to do that by iterating the TestSet, see if it contains an attachment and if so, add it to a list.

This post on SQA Forums explains how you can directly retrieve the list of attachments from a given testset by using the TestSetTreeManager and retrieving a TestSet from it by node id. Then all attachment from this node can be gathered at once:

Snippet:

Set TestSetTreeManager = TDConnection.TestSetTreeManager
Set TestSetFolder = TestSetTreeManager.NodeById(provideId)
If TestSetFolder.HasAttachments Then
    Set Attachment = TestSetFolder.Attachments
    Set AttachmentList = Attachment.NewList(" ")
End if




About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK