By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Early binding arrays, best technique

P: n/a
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?

--
mark
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

"mark" wrote:
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?

--
mark

Nov 21 '05 #2

P: n/a
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
"mark" <ma**@discussions.microsoft.com> wrote in message
news:7F**********************************@microsof t.com...
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?

--
mark

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.