Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get device name using twain in vb.net her is my code but its not working.....
VB
Dim N As Long
        Dim i As Long

        N = AxTwain1.DeviceCount
        If N > 0 Then
            ComboBox1.Items.Clear()
            For i = 1 To N
                ' Note use of get_ prefix for indexed property DeviceName
                ComboBox1.Items.Add(AxTwain1.get_DeviceName(i - 1))
            Next
            ComboBox1.SelectedIndex = 0


            ComboBox1.Items.Add("No TWAIN devices found")
            ComboBox1.SelectedIndex = 0

        End If
Posted
Comments
Michael_Davies 4-May-15 4:06am    
use the debugger and step thru the code, it may be that the for is not executing as the condition is satisfied if there is only one device.
lakshjoshi 4-May-15 6:32am    
i am using pen tablet and webcam even though its not list out why...?
Sinisa Hajnal 4-May-15 8:12am    
Some devices may not be recognized (or do not support) twain. Also, your code looks like VB6 and not .NET

Remove N and i declarations, write for i as Long = 0 to AxTwain1.DeviceCount-1...

Also, depending on your twain library, you could maybe get a list of device names and use for each.
lakshjoshi 4-May-15 9:22am    
done as per suggestion..but not worked, but i worked with web cam using twain its working fine,its capturing images and scaning but not showing in list why...?

1 solution

You code is incorrect. First, if N > 0, the index i should start from 0, not 1. Second, you should move ComboBox1.Items.Add("No TWAIN devices found") to else clause. Here is how I changed your code logic with Dynamic .NET TWAIN SDK[^]:

VB
dynamicDotNetTwain.OpenSourceManager()
        Dim N As Long
        Dim i As Long

        N = dynamicDotNetTwain.SourceCount
        If N > 0 Then
            ComboBox1.Items.Clear()
            For i = 0 To N
                ' Note use of get_ prefix for indexed property DeviceName
                Name = dynamicDotNetTwain.SourceNameItems(Convert.ToInt16(i))
                ComboBox1.Items.Add(Name)
                i += 1
            Next
        Else
            ComboBox1.Items.Add("No TWAIN devices found")
        End If

        ComboBox1.SelectedIndex = 0
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900