This example accepts four values from the user to specify the left start, top start, width and height of the area to be scanned in inches. Values are passed via SetScanCapability, which would scan the area specified without displaying the TWAIN UI.
Private Sub CmdSetLayout_Click()
Const CAP_SCAN_IMAGE_LAYOUT = 106
Const CAP_SCAN_IMAGE_HEIGHT = 3
Const CAP_SCAN_IMAGE_WIDTH = 4
Dim varScanWidth, varScanHeight As Variant
'Open scanner for capability check.
ImgScan1.OpenScanner
'Determine what width and height the scanner can support.
varScanWidth = ImgScan1.GetScanCapability(CAP_SCAN_IMAGE_WIDTH)
If VarType(varScanWidth) = vbError Then
MsgBox "Unable to get maximum width"
End If
varScanHeight = ImgScan1.GetScanCapability(CAP_SCAN_IMAGE_HEIGHT)
If VarType(varScanHeight) = vbError Then
MsgBox "Unable to get maximum height"
End If
'The user enters width and height values in a dialog box.
Dim sngLayout(4) As Single
sngLayout(0) = CSng(Text1.Text) 'left start
sngLayout(1) = CSng(Text2.Text) 'top start
sngLayout(2) = CSng(Text3.Text) 'width
sngLayout(3) = CSng(Text4.Text) 'height
'Validate values the user entered before trying to set them.
If sngLayout(0) + sngLayout(2) > varScanWidth Then
MsgBox "Too Wide"
Exit Sub
End If
If sngLayout(1) + sngLayout(3) > varScanHeight Then
MsgBox "Too Long"
Exit Sub
End If
ImgScan1.SetScanCapability CAP_SCAN_IMAGE_LAYOUT, sngLayout
End Sub