Saturday, May 8, 2010

Function to calculate the sum of numbers between 1 and 100 that are divisible by 4

Function SumOfNum(ByVal x As Integer) As Integer 

Dim i As Integer
SumOfNum = 0
For i = 1 To 100
If i Mod x = 0 Then
SumOfNum = SumOfNum + i
Else
SumOfNum = SumOfNum
End If
Next i 

End Function 

Private Sub Command1_Click()
Dim w As Integer
x = Text1.Text
w = SumOfNum(x)
Label1.Caption = w 

End Sub

No comments:

Post a Comment