I have been trying to figure this out for quite some time... Some help would be appreciated :)

intnumber = txtnum.Text
intcount = 1
Do While lngsum <= intnumber
 intcount = intcount + lngsum
 lngsum = lngsum + 2
Loop
lblsum.Caption = "The sum of the odd numbers is: " & intcount

Correct me if I'm wrong. The user enters a number and the app is supposed to add each odd number between 0 and the input? Your program, on the other hand, adds each even number less than or equal to the input then adds 1 to the total sum. To correct this, one way is that intcount = 1 should be lngsum = 1

:o I got it

Option Explicit
Dim intnumber As Integer
Dim lngsum As Long
Dim intcount As Integer

Private Sub cmdcalc_Click()
intcount = 0
intnumber = txtnum.Text
lngsum = 1
Do While lngsum <= intnumber
intcount = intcount + lngsum
lngsum = lngsum + 2
Loop
lblsum.Caption = "The sum of the odd numbers is: " & intcount
End Sub

Private Sub txtnum_Change()
lblsum.Caption = "The sum of the odd numbers is: "
End Sub

This will work just as well

lblsum.Caption = "The sum of the odd numbers is: " & round((intnumber / 2) + .1) ^ 2

Cheers

D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.