nigelandrewfoster
Well-known Member
- Joined
- May 27, 2009
- Messages
- 747
Hi. I am exploring execution time overheads using various structures of code. I came across this today - an Overflow error (on the highlighted line) caused simply by declaring data type. Can anyone explain it please?
When I run the code without declaring the arguments I am passing as integers (i.e. I leave them as variants) the code executes with no problems.
Thanks
When I run the code without declaring the arguments I am passing as integers (i.e. I leave them as variants) the code executes with no problems.
Thanks
Code:
Sub B()
Dim StartTime As Double
Dim SecondsElapsed As Double
Dim Count As Single
Dim Result As Single
Dim A As Integer, B As Integer, C As Integer, D As Integer, E As Integer, _
F As Integer, G As Integer, H As Integer, I As Integer, J As Integer
A = 1
B = 2
C = 3
D = 4
E = 5
F = 6
G = 7
H = 8
I = 9
J = 10
StartTime = Timer
For Count = 1 To 10000000
Result = Multiply(A, B, C, D, E, F, G, H, I, J)
Next
SecondsElapsed = Round(Timer - StartTime, 2)
MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation
End Sub
Function Multiply(a1 As Integer, a2 As Integer, a3 As Integer, a4 As Integer, a5 As Integer, _
a6 As Integer, a7 As Integer, a8 As Integer, a9 As Integer, a10 As Integer) As Single
[COLOR=#ff0000] Multiply = a1 * a2 * a3 * a4 * a5 * a6 * a7 * a8 * a9 * a10[/COLOR]
End Function