IEnumerable Option strict late binding issue

Multi tool use


IEnumerable Option strict late binding issue
Private Sub EvaluateDistanceBetweenIrregularSpots(irregularWeldspots As IEnumerable)
For Each spot1 In irregularWeldspots
spot1.row("XUNIT") Is Nothing Then Continue For...
Issues for spot1.row("XUNIT")
as "Option strict On disallows late binding."
spot1.row("XUNIT")
What is the type of
spot1
and spot2
? Does that type have a member named row
? When you type the dot after either of them, what options does Intellisense give you?– jmcilhinney
9 hours ago
spot1
spot2
row
Ienumerable type and we just have selected Option strict to ON after that this issue came
– PrasadK
9 hours ago
1 Answer
1
The IEnumerable interface used in your code is not generic, which means that the type of objects in it are unknown.
When you do For Each spot1 In irregularWeldspots
the actual type of spot1 is unknown so the Object
type is assumed. There is no "row" property in class Object so that's why you get the error.
For Each spot1 In irregularWeldspots
Object
There are a couple of ways you can resolve the error. The preferred way would be to use the generic IEnumerable interface:
Private Sub EvaluateDistanceBetweenIrregularSpots(irregularWeldspots As IEnumerable(Of Spot))
For Each spot1 In irregularWeldspots
spot1.row("XUNIT") Is Nothing Then Continue For...
If for some reason you can't do this, you can always specify the type of the spot1 variable explicitely:
Private Sub EvaluateDistanceBetweenIrregularSpots(irregularWeldspots As IEnumerable)
For Each spot1 As Spot In irregularWeldspots
spot1.row("XUNIT") Is Nothing Then Continue For...
You can replace Spot
by the actual type of the spot1
variable.
Spot
spot1
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can u edit your post to add code formatting
– Gauravsa
9 hours ago