Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Option Strict Disallows Late Binding

Reply
 
Old 07-25-2009   #1 (permalink)
Paul Ilacqua


 
 

Option Strict Disallows Late Binding

The code below Fails to compile with option strict on... with off it is
fine. Where is the problem?

Function Find_In_List(ByVal alIn As ArrayList, ByVal iIndex As Integer,
ByVal sFindVal As String) As String
If alIn Is Nothing Then
Return ("")
End If
For i As Integer = 0 To alIn.Count - 1
If alIn.Item(i)(iIndex).ToString = sFindVal Then '---- Fails
Here
Find_In_List = alIn.Item(i)(0).ToString & "|" &
alIn.Item(i)(1).ToString & "|" & alIn.Item(i)(2).ToString
Exit For
End If
Next

End Function

Thanks
Paul


My System SpecsSystem Spec
Old 07-25-2009   #2 (permalink)
Family Tree Mike


 
 

Re: Option Strict Disallows Late Binding

Paul Ilacqua wrote:
Quote:

> The code below Fails to compile with option strict on... with off it is
> fine. Where is the problem?
>
> Function Find_In_List(ByVal alIn As ArrayList, ByVal iIndex As Integer,
> ByVal sFindVal As String) As String
> If alIn Is Nothing Then
> Return ("")
> End If
> For i As Integer = 0 To alIn.Count - 1
> If alIn.Item(i)(iIndex).ToString = sFindVal Then '---- Fails
> Here
> Find_In_List = alIn.Item(i)(0).ToString & "|" &
> alIn.Item(i)(1).ToString & "|" & alIn.Item(i)(2).ToString
> Exit For
> End If
> Next
>
> End Function
>
> Thanks
> Paul
The problem is that you are using ArrayList, rather than, for example,
List (of String). ArrayList is holding Objects in your case. This is
frowned upon unless you are forced to use .Net version 1.1.

--
Mike
My System SpecsSystem Spec
Old 07-25-2009   #3 (permalink)
Jack Jackson


 
 

Re: Option Strict Disallows Late Binding

On Sat, 25 Jul 2009 15:25:37 -0400, "Paul Ilacqua"
<pilacqu2@xxxxxx> wrote:
Quote:

>The code below Fails to compile with option strict on... with off it is
>fine. Where is the problem?
>
> Function Find_In_List(ByVal alIn As ArrayList, ByVal iIndex As Integer,
>ByVal sFindVal As String) As String
> If alIn Is Nothing Then
> Return ("")
> End If
> For i As Integer = 0 To alIn.Count - 1
> If alIn.Item(i)(iIndex).ToString = sFindVal Then '---- Fails
>Here
> Find_In_List = alIn.Item(i)(0).ToString & "|" &
>alIn.Item(i)(1).ToString & "|" & alIn.Item(i)(2).ToString
> Exit For
> End If
> Next
>
> End Function
>
>Thanks
>Paul
It looks to me like you have two problems here.

First, alIn.Item(i) is defined as type Object, and you are indexing
that object. You need to cast alIn.Item(0) to whatever it really is.
You could use the generic List(Of ) instead to tell the compiler
explicitly what is in the list.

Second, once you get the indexed value, you convert it to a String
with ToString and then compare that with an Integer. Assuming it
really contains an Integer, you need to cast it to an Integer.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Late Binding with IDispatch based com objects PowerShell
RC2 and late-binding / loose types PowerShell
Powershell interacting with COM automation with late-binding? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46