![]() |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
1 week past, any feedback?
|
|
#3
|
||||
|
||||
|
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.
Based on code by msdixon found on Experts Exchange: http://www.experts-exchange.com/Prog..._20889243.html
__________________
-spike _/\_ |
|
#4
|
|||
|
|||
|
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));
}
[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
Last edited by samb; 08-22-2008 at 10:26 PM. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|