I am making a Visual Basic.NET program to do the following:
1. Give Total number of all ODD digits and EVEN digits together
2. Give Sum of all ODD digits
3. Give Sum of all EVEN digits
I have two text boxes for a user to input a start value and end value for him/her to get the above calculations between the range of start value and end value.
I have managed to get code for sum of all odd digits or even digits from 1 to any end value input. How do i get sum from any start value?
Here is my code, what i did:
Public Class Form1 Private Sub btnCompute_Click(ByVal sender As Object, _ ByVal e As System.EventArgs) Handles btnCompute.Click Dim sum As Integer = 0 Dim stepAmt As Integer = 0 Dim number As Integer = 0 Dim x As Integer = 0 number = Val(Me.txtNumber.Text) For x = 1 To number Step 2 sum += x Next Me.lblMessage.Text = "Odd numbers sum: " Me.lblSum.Text = sum End Sub Private Sub txtNumber_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtNumber.TextChanged Me.lblMessage.Text = "" Me.lblSum.Text = "" End Sub End Class