ぴえろっちが問題をくれた。その1のつづき。

Public Module Program

Public Sub Main()

Dim n1 As Long
Dim n2 As Long
Dim limitValue As Long

n1 = 1
n2 = 2
limitValue = 4000000

Dim result As Long

result = Calc(n1, n2, limitValue)

System.Console.WriteLine("Result : " & result)

End Sub


Public Function Calc _
(ByVal n1 As Long, _
ByVal n2 As Long, _
ByVal limitValue As Long) _
As Long

Dim result As Long

result = 0

Dim x1 As Long
Dim x2 As Long

x1 = n1
x2 = n2

Do While x1 <= limitValue

If x1 Mod 2 = 0 Then result = result + x1

x2 = x1 + x2
x1 = x2 - x1

Loop

Calc = result

End Function

End Module

もうちょっとさくっとかけないかな・・・。