Early binding arrays, best technique

G

Guest

I understand that writing programs with option strict on is the best way to
obtain stable applications. I have also found the applications to run much
faster.

Option strict on disallows late binding, so if I have an array with class
level scope and I am operating on that array at procedure level I fabricate a
"dummy array" and copy the class level array into it. Then after performing
the task I can copy the "dummy array" back into the global array. For example:

Dim A(10,10)

SUB

Dim localC(10,10) As Double
Dim earlybinda(10,10) As Double

Array.Copy(globalA, earlybinda, globalA.length)
For i = 1 To 10
For j = 1 To 10
localC(i, j) = Scalar * earlybinda(i, j)
Next
Next

Array.Copy(localC, globalA, (localC.length)

END

IS THIS THE BEST WAY TO AVOID LATE BINDING WHEN WORKING WITH ARRAYS?
 
G

Guest

This suppose to work:

Dim A(10, 10) As Double

SUB
For i = 1 To 10
For j = 1 To 10
A(i, j) = scalar * A(i, j)
Next
Next
END SUB
 
B

Bob

Hi Mark,
Late binding, it seems to me, is more related to data type then scope.
If you are in a situation where you don't know what type of data you are
stuffing into a variable then you would declare this variable to be of type
'Object' and with late binding you could throw anything at it.
But you have to ask when are you ever truly in this situation?
Most times you know what sort of object is coming at you.
The CType(myvariable,datatype) takes care of most conversions. eg reading a
number from a database record into a class property that is expecting an
enumeration.
eg.
Unit.Status = CType(cmdSource.GetOracleNumber(12).Value, clsEvent.eSeverity)

Regarding your code,

Why don't you pass a reference to your class level array into your
subroutine instead of doing two copies?

(Assuming that you don't want to access the class array directly in the
subroutine to keep the code 'readable')

HTH

Regards

Bob
 

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

Top