Twain Feeder: Tutorial #1 (Visual Basic)

Take the following steps to start a project and to add some code that acquires the images using Fast Twain:

1.

Start Visual Basic.

2.

Add the LEAD RasterTwain Object Library and LEAD Raster Variant Object Library to your project.

 

On the Project pull-down menu, use the References option, and select the LEAD RasterTwain Object Library.

 

On the Project pull-down menu, use the References option, and select the LEAD Raster Variant Object Library.

3.

Add the following code to the general declarations section of your project:

Public TwainCap As New LEADTwainCapability_U
Public WithEvents RasterTwain As LEADRasterTwain_U

4.

Add the following code to the main form's Load procedure:

Set RasterTwain = New LEADRasterTwain_U
RasterTwain.InitSession hWnd
RasterTwain.EnableMethodErrors = False

5.

Add the following code to the main form's Unload procedure:

RasterTwain.EndSession

6.

Add the following button:

 

 

Name

Caption

 

 

cmdAcquire

Acquire

 

7.

Code the Acquire control's Click procedure as follows. In online help, you can use the Edit pull-down menu to copy the block of code.

 

Private Sub cmdAcquire_Click()
   Dim bEnable As Boolean
   Dim nRet As Integer

   RasterTwain.SelectSource
   
   TwainCap.CapInfo.Capability = L_CAP_AUTOFEED
   TwainCap.CapInfo.ConType = L_TWON_ONEVALUE

   bEnable = True
   Dim RasVar As New LEADRasterVariant_U
   RasVar. = VALUE_BOOLEAN
   RasVar. = bEnable
   
   TwainCap.CapOneValue.OneValItemType = L_TWTY_BOOL
   TwainCap.CapOneValue.OneValCapValue = RasVar

   nRet = RasterTwain.SetCapability2(TwainCap, L_LTWAIN_CAPABILITY_SET) 
   If nRet = 0 Then
      MsgBox "AutoFeed capability is enabled"
   Else
      MsgBox "Can't enable AutoFeed capability"
   End If

   ' try to acquire pages using AutoFeed capability
   RasterTwain.Acquire L_LTWAIN_SHOW_USER_INTERFACE Or L_LTWAIN_MODAL_USER_INTERFACE
End Sub