-
February 2nd, 2011, 11:27 PM
#1
HELP with For Next...
Okay, so I have to create program that adds the whole numbers from 1 to 1000 and displays the sum in the label. Create a variation of this program that allows the user to specify any starting whole number and any ending whole number (10,000 or lower) and then adds all the whole numbers in that range. Allow for the possibility that a user may start with a high number and end with a low number. Format the label so that commas are displayed and there are no decimal places showing. I need help with the codes.
So far I'v come up with this
For i = 1 to 1000
Next
-
February 3rd, 2011, 12:16 AM
#2
Re: HELP with For Next...
So, what's the problem. That looks OK to me.
If you run into other problems, post them, and we'll help.
-
February 3rd, 2011, 04:07 PM
#3
Re: HELP with For Next...
Public Function AddRange(ByVal LowNum As Long, ByVal HighNum As Long)as Long
dim Result as Long
Result = 0
For i as integer = LowNum to HighNum
Result += i
Next i
AddRange=Result
End Function
-
February 3rd, 2011, 04:57 PM
#4
Re: HELP with For Next...
Quote your post, and then MINE:
Code:
Public Function AddRange(ByVal LowNum As Long, ByVal HighNum As Long)as Long
dim Result as Long
Result = 0
For i as integer = LowNum to HighNum
Result += i
Next i
AddRange=Result
End Function
-
February 3rd, 2011, 04:58 PM
#5
Re: HELP with For Next...
Either you have to check BEFORE you call that sub, or FIRST THING inside of it.
What if Low>High? Switch them...
If you can't grasp these simple concepts, you should go back to the books
-
February 3rd, 2011, 05:00 PM
#6
Re: HELP with For Next...
Right ... So far that is correct...
Allow for the possibility that a user may start with a high number and end with a low number.
Hint for this...
Code:
If LowNum > HighNum Then
End If
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|