Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Topics

Recent Status Updates

View All Updates

- - - - -

Program to give sum of all odd and even digits


This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 Gooer


    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 09 December 2015 - 08:00 PM

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

        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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download