GetPresentationCount Example for VB.NET

'LEADDICOMNet1 is a predefined LEADDicomNet object
Private Sub TestGetPresentationCount ( )
   Const UID_CT_IMAGE_STORAGE As String = "1.2.840.10008.5.1.4.1.1.2"
   ' Computed Tomography Image Storage
   Dim x As Integer
   Dim id As Short
   Dim maxid As Short
   Dim out As String

   'create the Associate Class as Request
   LEADDICOMNet1.CreateAssociate(True)
   'set the Associate to the default
   LEADDICOMNet1.DefaultAssociate(LEADDICOMNet1.hPDU)

   'get current id's and display them
   out = ""
   maxid = 0
   For x = 0 To LEADDICOMNet1.GetPresentationCount(LEADDICOMNet1.hPDU) - 1
      id = LEADDICOMNet1.GetPresentationID(LEADDICOMNet1.hPDU, x)
      out = out & id
      out = out & Chr(13)
      'store the highest id
      If id > maxid Then
         maxid = id
      Next
   MessageBox.Show(out)

   id = maxid + 2 'id must be unique and odd number
   'change the some ids and then display them all
   For x = 0 To LEADDICOMNet1.GetPresentationCount(LEADDICOMNet1.hPDU) - 1
      LEADDICOMNet1.SetPresentationID(LEADDICOMNet1.hPDU, x, id)
      id = id + 2 'id must be odd number
   Next
   out = ""
   For x = 0 To LEADDICOMNet1.GetPresentationCount(LEADDICOMNet1.hPDU) - 1
      out = out & LEADDICOMNet1.GetPresentationID(LEADDICOMNet1.hPDU, x)
      out = out & Chr(13)
   Next
   MessageBox.Show(out)

   'add a presentation context
   out = "" LEADDICOMNet1.AddPresentation(LEADDICOMNet1.hPDU, 1, LTDNCLib.AssociateAcceptConstants.PDU_ACCEPT_RESULT_SUCCESS, UID_CT_IMAGE_STORAGE)
   For x = 0 To LEADDICOMNet1.GetPresentationCount(LEADDICOMNet1.hPDU) - 1
      out = out & LEADDICOMNet1.GetPresentationID(LEADDICOMNet1.hPDU, x)
      out = out & Chr(13)
   Next
   MessageBox.Show(out)

   'delete the one we added
   out = "" LEADDICOMNet1.DeletePresentation(LEADDICOMNet1.hPDU, 1)
   For x = 0 To LEADDICOMNet1.GetPresentationCount(LEADDICOMNet1.hPDU) - 1
      out = out & LEADDICOMNet1.GetPresentationID(LEADDICOMNet1.hPDU, x)
      out = out & Chr(13)
   Next
   MessageBox.Show(out)

   LEADDICOMNet1.FreeAssociate(LEADDICOMNet1.hPDU)
End Sub