![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 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 Specs![]() |
| | #3 (permalink) |
| | 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 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 Specs![]() |
![]() |
| 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 | |||