Dosadi home  

Go Back   Dosadi Forum > Dosadi > EZTwain-X ActiveX Control

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 06-05-2008, 07:38 AM
riona26 riona26 is offline
Participant
 
Join Date: Nov 2007
Posts: 6
Default Get InstalledSources in vb2008

Hi there,

I followed the example post in Techincal Reference for InstalledSources. After i upgraded my project from VB6 to VB2008, i got the following error once VB process the code "devs = EZTwain.InstalledSources":

"Unable to cast object of type 'System.Object[*]' to type 'System.Object[]'."

i've tried to declare devs as 2 dimension array, but i still got similar error.

Please advice for solution.

Regards,
Riona
Reply With Quote
  #2  
Old 06-13-2008, 03:57 PM
riona26 riona26 is offline
Participant
 
Join Date: Nov 2007
Posts: 6
Angry

1 week past, any feedback?
Reply With Quote
  #3  
Old 07-09-2008, 11:28 AM
Spike's Avatar
Spike Spike is offline
Administrator
 
Join Date: Oct 2004
Location: Northampton, MA
Posts: 1,664
Cool Using InstalledSources property in VB.NET

Hi Riona - sorry for the long delay. I have to admit, I have no clue. Those don't even look like VB types, but then this is .NET. And I am not particularly fluent in VB.NET (slightly more in C#, but not much...)

Aha - I think maybe the problem is that InstalledSources returns a variant array with a lower-bound of 1, which is of course standard for VB. In .NET, there are no variants (System.Object plays that role, sort of), and all arrays are 0-indexed, so... MS in their collective wisdom decided this particular conversion shall not be done automatically.

How about something like this:
Code:
      Dim obj As Object() = EZTwain.InstalledSources()
      Dim strRet(obj.Length) As String

      Dim i As Integer
      For i = 0 To obj.Length - 1
         strRet(i) = Convert.ToString(obj(i+1))
      Next
      ' strRet now contains string array.
I'm not sure you even need that Convert.ToString.
Based on code by msdixon found on Experts Exchange:
http://www.experts-exchange.com/Prog..._20889243.html
__________________
-spike _/\_
Reply With Quote
  #4  
Old 08-22-2008, 09:32 PM
samb samb is offline
Contributor
 
Join Date: Aug 2008
Location: Spokane
Posts: 25
Default

Not sure if Spikes solution worked, or if Riona found a different solution, but in case anyone else runs into this.

In C# just doing Object[] list = EZTwain.InstalledSources() will crash giving the exception that Riona reported, so I think Spike's suggestion will die on the first line.

I fought this problem for a few hours a month or so ago and never got anywhere. Finally today I got back to working on it, did a search on that exception message and found a solution that works in c#. Should be easily converted to vb.net, but I'm a bit rusty on that syntax.

Code:
Array sourceList = (Array)(EZTwainX.InstalledSources);
foreach (Object source in sourceList)
{
     MessageBox.Show((string)(source));
}
Basically instead of declaring it as an array of objects, you can just declare it as an Array without providing any element type.

[Edit]
Found out I still have a VB.Net IDE on my system, so here's the syntax:
Code:
Dim sourceList As Array
sourceList = EZTwainX.InstalledSources
Dim source as Object
For Each source In sourceList
     MsgBox(source.ToString())
Next
[/Edit]

Last edited by samb; 08-22-2008 at 10:26 PM.
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:44 PM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Content ©2007-2009 Dosadi