Loading a Data Set (Visual Basic)
Take the following steps to start a project and to add some code that loads a DICOM Data Set and prints information about the data set:
| 1. | Start Visual Basic. | |
| 2. | Add the LEAD COM Objects to your project. | |
| 
 | On the Project pull-down menu, use the Components option, and select the LEAD Raster View Control (14.5). | |
| 
 | On the Project 
 pull-down menu, use the References 
 option, and select the following: | |
| 3. | Select the LEAD Raster View Control, then add the control to your main form. | |
| 4. | Add a command button to your form and name it as follows: | |
| 
 | Name | Caption | 
| 
 | LoadImage | Load Image | 
| 5. | Add the following initialization code to the main form's Load procedure. In online help, you can use the Edit pull-down menu to copy the block of code. | |
‘global declaration
Private WithEvents LEADDICOM1 As LEADDicomDS
Private Sub Form_Load()
    'Unlock DICOM support.
    'Note that this is a sample key, which will not work in your toolkit.
    Dim Factory As New LEADDicomFactory
    Dim DicomKernel As LEADDicomKernel
    Dim szLic As String
    
    szLic = "LEADTOOLS OCX Copyright (c) 1991-2005 LEAD Technologies, Inc."
    Set Factory = CreateObject("LEADDicomFactory.LEADDicomFactory")
    Set DicomKernel = Factory.CreateObject ("LEADDicomKernel.LEADDicomKernel", szLic)
    Set LEADDICOM1 = Factory.CreateObject ("LEADDicomDS.LEADDicomDS", szLic)
    DicomKernel.UnlockSupport L_SUPPORT_MEDICAL, "TestKey"
End Sub
| 6. | Code the LoadImage button's click procedure as follows: | 
Private Sub LoadLead_Click()
    Dim nRet As Integer
    Dim lCount As Integer
    Dim Result As Boolean
    LEADDICOM1.EnableMethodErrors = False
    nRet = LEADDICOM1.LoadDS ("D:\lead14\dist\images\dicom\image1.dic", 0)
    If (nRet <> DICOM_SUCCESS) Then
        MsgBox "Error " & CStr(nRet) & " loading file!"
    End If
    lCount = LEADDICOM1.GetModuleCount
    LEADDICOM1.FindIndexModule 0
    Result = LEADDICOM1.SetCurrentElement(LEADDICOM1.CurrentModule.Element(0).hElement)
    If (Result = True) Then
        MsgBox "There are " & CStr(lCount) & " modules in this data set." & (Chr(13)) & _
        "The first module has " & CStr(LEADDICOM1.CurrentModule.ElementCount) & _
        " elements." & (Chr(13)) & "The first element has: " & (Chr(13)) & "Tag number:" & _
        Hex(LEADDICOM1.CurrentElement.Tag) & (Chr(13)) & "VR: " & _
        Hex(LEADDICOM1.CurrentElement.VR)
    End If
    LEADDICOM1.EnableMethodErrors = True
End Sub
| 7. | Run your program to test it. | 
| 8. | Save the project to use as a starting point for other tasks in this tutorial. |