Late Binding

L

lgbjr

hi All,

I've decided to use Options Strict ON in one of my apps and now I'm trying
to fix a late binding issue. I have 5 integer arrays:

dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as integer

The integers in these arrays are actually pointers to different columns of
data in a text file.

I create an array of these arrays:

Dim HIndex() as Array = {IA1, IA2, IA3, IA4, IA5}

Then I use two loops to retrieve the integers from the aray of arrays:

Dim xHeader() as String
Dim T_xHeader as ArrayList

For s = 0 to 4
Do some stuff
For i = 0 to HIndex(s).Length -1
Do some stuff
T_xHeader.Add(xHeader(HIndex(s)(i))) 'Late Binding Here
Next i
Do some stuff
Next s

So, HIndex(s)(i) actually points to an value in xHeader, which is then added
to T_xHeader.

This all works fine, but, becasue I'm dimensioning HIndex as an array, I'm
getting a late binding error.

I can't figure out how to dimension HIndex to something other than array, in
order to avoid the late binding.

Any ideas would be greatly appreciated!!

TIA
Lee
 
L

lgbjr

Hi All,

I'm playing with some ideas regarding my first post.

The first thing I'm trying to do is get rid of the Array of Arrays (as it's
not CLS compliant). So, I'm adding a string array with the names of the
integer arrays:

Dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as integer
Dim Sname as String() = {"IA1", "IA2", "IA3", "IA4", "IA5"}

Dim xHeader() as String
Dim T_xHeader as ArrayList

For s = 0 to Sname.Length - 1
Do some stuff
For i = 0 to CType(Sname(s).Clone, Array).Length - 1
Do some stuff
T_xHeader.Add(xHeader(Sname(s).Clone(i))) 'Late Binding Here
Next i
Do some stuff
Next s

So, I've managed to get rid of the array of arrays, but I still have the
late binding issue.

What I'm tring to avoid is this:

For s = 0 to Sname.Length - 1
Do some stuff
if Sname(s) = "IA1" Then
For i = 0 to IA1.Length - 1
Do some stuff
T_xHeader.Add(xHeader(IA1(i))) 'Early Binding
Next i
Elseif Sname(s) = "IA2" then
For i = 0 to IA2.Length - 1
Do some stuff
T_xHeader.Add(xHeader(IA2(i))) 'Early Binding
Next i
Elseif Sname(s) = "IA3" then
For i = 0 to IA3.Length - 1
Do some stuff
T_xHeader.Add(xHeader(IA3(i))) 'Early Binding
Next i
Elseif Sname(s) = "IA4" then
For i = 0 to IA4.Length - 1
Do some stuff
T_xHeader.Add(xHeader(IA4(i))) 'Early Binding
Next i
Elseif Sname(s) = "IA5" then
For i = 0 to IA5.Length - 1
Do some stuff
T_xHeader.Add(xHeader(IA5(i))) 'Early Binding
Next i
Endif
Do some stuff
Next s

the reason I'm trying to avoid this is to prevent lots of necessary code
changes if the number of Integer arrays changes. Using my first (late
binding) method, the only changes would be to dimension another Integer
array and add it's name to the string array.

TIA
Lee
 
C

Cor Ligthert

Lee,

See my earlier message, know that IList is the interface that almost every
standard array and collection implements except the VB collection.

And therefore can be used.

Cor
 
H

Herfried K. Wagner [MVP]

lgbjr said:
I've decided to use Options Strict ON in one of my apps and now I'm trying
to fix a late binding issue. I have 5 integer arrays:

dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as integer

The integers in these arrays are actually pointers to different columns of
data in a text file.

I create an array of these arrays:

Dim HIndex() as Array = {IA1, IA2, IA3, IA4, IA5}

Then I use two loops to retrieve the integers from the aray of arrays:

Dim xHeader() as String
Dim T_xHeader as ArrayList

For s = 0 to 4
Do some stuff
For i = 0 to HIndex(s).Length -1
Do some stuff
T_xHeader.Add(xHeader(HIndex(s)(i))) 'Late Binding Here

The best solution is to create a jagged array (an array of arrays):

\\\
Dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) As Integer
Dim HIndex()() As Integer = {IA1, IA2, IA3, IA4, IA5}
///
 
C

Cor Ligthert

Herfried,
The best solution is to create a jagged array (an array of arrays):

\\\
Dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) As Integer
Dim HIndex()() As Integer = {IA1, IA2, IA3, IA4, IA5}
///
You know my question when there is written "the best" without any
explanation.

The way you write it means under all conditions and without any execption.

You know him, however when there is the slightest doubt

Why?

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Cor,
The OP stated he wanted an "array of these arrays".
| I create an array of these arrays:
| Dim HIndex() as Array = {IA1, IA2, IA3, IA4, IA5}

A Jagged or Ragged array is an "array of arrays".
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconDeclaringArrays.asp

Ergo the OP wants a Jagged array as Herfried shows.

Dim HIndex() as Integer() = {IA1, IA2, IA3, IA4, IA5}

or

Dim HIndex()() as Integer = {IA1, IA2, IA3, IA4, IA5}


Hope this helps
Jay


| Herfried,
| >
| > The best solution is to create a jagged array (an array of arrays):
| >
| > \\\
| > Dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) As Integer
| > Dim HIndex()() As Integer = {IA1, IA2, IA3, IA4, IA5}
| > ///
| >
| You know my question when there is written "the best" without any
| explanation.
|
| The way you write it means under all conditions and without any execption.
|
| You know him, however when there is the slightest doubt
|
| Why?
|
| Cor
|
|
 
C

Cor Ligthert

Jay,
The OP stated he wanted an "array of these arrays".
| I create an array of these arrays:
| Dim HIndex() as Array = {IA1, IA2, IA3, IA4, IA5}

I know, however he showed his code that looked like this.
Then I use two loops to retrieve the integers from the aray of arrays:
Dim xHeader() as String
Dim T_xHeader as ArrayList

I won't say that the answer from Hefried can not be right, however in my
opinion is it the situation you use it where that is. You will always see
this question from me, when somebody says it is the *best* while he is not
saying why, or in what situation. (Who ever it is).

You would know that I always tell in a completly static situation to use the
way Herfried describes and in a dynamic situation at least not to use a
static array in the dynamic part.

Cor
 
J

Jay B. Harlow [MVP - Outlook]

Cor,
| >Dim T_xHeader as ArrayList
Is part of his output, not part of his input. Hence I don't see it as part
of his question.

By output I mean it is where he is placing the results of his jagged array.
By input I mean the jagged array itself. His output could have just as
easily been a file or another fixed array!

As I stated, he states he wants an array of arrays, which is what Herfried &
I showed.

Hope this help
Jay



| Jay,
|
| >The OP stated he wanted an "array of these arrays".
| >| I create an array of these arrays:
| >| Dim HIndex() as Array = {IA1, IA2, IA3, IA4, IA5}
|
| I know, however he showed his code that looked like this.
|
| >Then I use two loops to retrieve the integers from the aray of arrays:
| >Dim xHeader() as String
| >Dim T_xHeader as ArrayList
|
| I won't say that the answer from Hefried can not be right, however in my
| opinion is it the situation you use it where that is. You will always see
| this question from me, when somebody says it is the *best* while he is not
| saying why, or in what situation. (Who ever it is).
|
| You would know that I always tell in a completly static situation to use
the
| way Herfried describes and in a dynamic situation at least not to use a
| static array in the dynamic part.
|
| Cor
|
|
 
C

Cor Ligthert

Jay,

The question is in my opinion a late binding question (see the subject) not
an array question.

When you say like Herfried that, using a jagged array is always the best
solution to overcome late bindings problems, than I have nothing more to
discus.
The best solution is to create a jagged array (an array of arrays):

That maybe the jagged array is the best solution for this problem, can be.
However, does not for me answer his more implicit question how to overcome
late binding in general. I nowhere saw that in yours and either in Herfrieds
text.

When it is possible, than I think that it is *better* to learn how to fish
than to give a fish.

I hope this helps

Cor
 
L

lgbjr

Hi All,

Cor, you are correct, the issue was really related to late binding, though I
understand why Jay and Herfield hit on the jagged array.

But, As I posted earlier, I want to stay away from the jagged array, as it's
not CLS compliant.

I had to move onto something else temporarily, but I'll post back tomorrow
with any questions regarding Cor's possible solution!

Thanks

Lee
 
H

Herfried K. Wagner [MVP]

Cor,

Cor Ligthert said:
The question is in my opinion a late binding question (see the subject)
not an array question.

The question is about

| [...] now I'm trying to fix a late binding issue
| [...]
| This all works fine, but, becasue I'm dimensioning HIndex as an array,
| I'm getting a late binding error.
|
| I can't figure out how to dimension HIndex to something other than
| array, in order to avoid the late binding.

All I did was answering this question.
When you say like Herfried that, using a jagged array is always the best
solution to overcome late bindings problems, than I have nothing more to
discus.

I don't think that anybody here would say that. We are talking about the
concrete question posted by the OP which was about how to fix a certain
late-binding problem.
That maybe the jagged array is the best solution for this problem

Nobody except you is talking about something else than "this problem".
When it is possible, than I think that it is *better* to learn how to fish
than to give a fish.

I don't see how 'IList' fits into "how to learn to fish", moreover I think
it's misleading because it's not appropriate for the OP's problem.

Just my 2 Euro cents again...
 
H

Herfried K. Wagner [MVP]

lgbjr said:
But, As I posted earlier, I want to stay away from the jagged array, as
it's not CLS compliant.

CLS-compliance is important for "interfaces" only, which means that a class
library's public methods, for example, should not return jagged arrays.
However, there is no problem with using jagged arrays in an internal
implementation.
 
C

Cor Ligthert

Herfried,
moreover I think it's misleading because it's not appropriate for the OP's
problem.

Have a look at the message from the OP, (Lee), that was sent before your
message.

I hope that this previous message from you gives a wrong impression about
you.

Cor
 
H

Herfried K. Wagner [MVP]

Cor Ligthert said:
Have a look at the message from the OP, (Lee), that was sent before your
message.

I hope that this previous message from you gives a wrong impression about
you.

Huh?! I read the OP's message...
 
J

Jay B. Harlow [MVP - Outlook]

Cor & lgbjr,
| The question is in my opinion a late binding question (see the subject)
not
| an array question.
As you may know you use Option Strict On to avoid late binding! Simple,
isn't it.

From there you get into specific examples of late binding, such as this
Jagged Array, which again Herfried & I answered how to avoid late binding in
this specific situation

I hope you will agree that there is no single simple answer on how to avoid
Late Binding, other then to turn Option Strict On & handle each of the Late
Binding errors in turn...

Hope this helps
Jay


| Jay,
|
| The question is in my opinion a late binding question (see the subject)
not
| an array question.
|
| When you say like Herfried that, using a jagged array is always the best
| solution to overcome late bindings problems, than I have nothing more to
| discus.
|
| > The best solution is to create a jagged array (an array of arrays):
|
| That maybe the jagged array is the best solution for this problem, can be.
| However, does not for me answer his more implicit question how to overcome
| late binding in general. I nowhere saw that in yours and either in
Herfrieds
| text.
|
| When it is possible, than I think that it is *better* to learn how to fish
| than to give a fish.
|
| I hope this helps
|
| Cor
|
|
 
J

Jay B. Harlow [MVP - Outlook]

lgbjr,
| But, As I posted earlier, I want to stay away from the jagged array, as
it's
| not CLS compliant.
Where do you get that impression???

According to The Common Language Infrastructure Annotated Standard:
<quote>NOTE: So-called "jagged arrays" are CLS-compliant, but when
overloading multiple array types they are one-dimensional, zero-based arrays
of type System.Array.</quote>

Which I read to mean that the jagged array "Integer()()" is implemented as
an "System.Array of System.Array Of Integer", of course if you look at the
IL shows this is how they are implemented! Its just that C# & VB.NET offers
syntactical sugar to simplify it to Integer()() or int[][]. As you found
putting an array, any array into a System.Array variable requires late
binding, if you put the array into a strongly typed variable, such as
Integer()(), then you avoid the late binding. Also using strongly typed
variables may enable the compiler to use array specific IL instructions
instead of the methods on System.Array...

Hope this helps
Jay


| Hi All,
|
| Cor, you are correct, the issue was really related to late binding, though
I
| understand why Jay and Herfield hit on the jagged array.
|
| But, As I posted earlier, I want to stay away from the jagged array, as
it's
| not CLS compliant.
|
| I had to move onto something else temporarily, but I'll post back tomorrow
| with any questions regarding Cor's possible solution!
|
| Thanks
|
| Lee
|
| | > Jay,
| >
| > The question is in my opinion a late binding question (see the subject)
| > not an array question.
| >
| > When you say like Herfried that, using a jagged array is always the best
| > solution to overcome late bindings problems, than I have nothing more to
| > discus.
| >
| >> The best solution is to create a jagged array (an array of arrays):
| >
| > That maybe the jagged array is the best solution for this problem, can
be.
| > However, does not for me answer his more implicit question how to
overcome
| > late binding in general. I nowhere saw that in yours and either in
| > Herfrieds text.
| >
| > When it is possible, than I think that it is *better* to learn how to
fish
| > than to give a fish.
| >
| > I hope this helps
| >
| > Cor
| >
|
|
 
J

Jay B. Harlow [MVP - Outlook]

Hmm...
| Which I read to mean that the jagged array "Integer()()" is implemented as
| an "System.Array of System.Array Of Integer", of course if you look at the
| IL shows this is how they are implemented!
Reading that just now, it doesn't make as much sense as I thought it did
when I wrote it. :-(

Reading the annotation accompanying Rule 16 in the Common Language
Infrastructure Annotated Standard it appears I was partially correct. What
I'm not certain about is if you do not overload a method on Jagged arrays if
the method is CLS compliant or not. It definitely appears if you overload a
method based on Jagged Arrays they are definitely not CLS compliant.

For example:

Public Compliant

Public Sub Sum(ByVal values As Integer()())
End Sub

End Class

Public Class NoneCompliant

Public Sub Sum(ByVal values As Integer()())
End Sub

Public Sub Sum(ByVal values As Single()())
End Sub

End Class

The way I am understanding the standard, the NoneCompliant class is not
compliant as both methods are treated as "Sum(ByVal values As
System.Array())", while the Compliant class may be compliant as there is
only a single method (its not overloaded)...

I'll have to see if I can find more info on this. Also I would be curious if
..NET 2.0 has clarified this any...

Either way, as was suggested, if the jagged array is a private
implementation detail of the type or method (its not Publicly exposed) then
the entire discussion of it being compliant or not, although interesting, is
largely academic.

Hope this helps
Jay



| lgbjr,
|| But, As I posted earlier, I want to stay away from the jagged array, as
| it's
|| not CLS compliant.
| Where do you get that impression???
|
| According to The Common Language Infrastructure Annotated Standard:
| <quote>NOTE: So-called "jagged arrays" are CLS-compliant, but when
| overloading multiple array types they are one-dimensional, zero-based
arrays
| of type System.Array.</quote>
|
| Which I read to mean that the jagged array "Integer()()" is implemented as
| an "System.Array of System.Array Of Integer", of course if you look at the
| IL shows this is how they are implemented! Its just that C# & VB.NET
offers
| syntactical sugar to simplify it to Integer()() or int[][]. As you found
| putting an array, any array into a System.Array variable requires late
| binding, if you put the array into a strongly typed variable, such as
| Integer()(), then you avoid the late binding. Also using strongly typed
| variables may enable the compiler to use array specific IL instructions
| instead of the methods on System.Array...
|
| Hope this helps
| Jay
|
|
| || Hi All,
||
|| Cor, you are correct, the issue was really related to late binding,
though
| I
|| understand why Jay and Herfield hit on the jagged array.
||
|| But, As I posted earlier, I want to stay away from the jagged array, as
| it's
|| not CLS compliant.
||
|| I had to move onto something else temporarily, but I'll post back
tomorrow
|| with any questions regarding Cor's possible solution!
||
|| Thanks
||
|| Lee
||
|| || > Jay,
|| >
|| > The question is in my opinion a late binding question (see the subject)
|| > not an array question.
|| >
|| > When you say like Herfried that, using a jagged array is always the
best
|| > solution to overcome late bindings problems, than I have nothing more
to
|| > discus.
|| >
|| >> The best solution is to create a jagged array (an array of arrays):
|| >
|| > That maybe the jagged array is the best solution for this problem, can
| be.
|| > However, does not for me answer his more implicit question how to
| overcome
|| > late binding in general. I nowhere saw that in yours and either in
|| > Herfrieds text.
|| >
|| > When it is possible, than I think that it is *better* to learn how to
| fish
|| > than to give a fish.
|| >
|| > I hope this helps
|| >
|| > Cor
|| >
||
||
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top