| | |
Adding the sum of odd numbers. Please help
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2007
Posts: 22
Reputation:
Solved Threads: 0
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
Last edited by t3hfr3ak; Apr 19th, 2007 at 12:02 am.
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 There are 10 types of people: those who understand Binary and those who don't!
•
•
Join Date: Apr 2007
Posts: 22
Reputation:
Solved Threads: 0
: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 ![]() |
Similar Threads
- Loop counting odd and even numbers (C++)
- Little bit of Homework Help would be greatly appreciated (C++)
- induction (Computer Science)
- Help with C++ code (C++)
- print odd and even numbers (Assembly)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Drawing curves with Picbox.Line
- Next Thread: suggestion please!!!!
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





