CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Apr 2010
    Posts
    3

    Cool visual basic program

    hello,
    how can we create a vb 6 program to sum 1 to 100 natural numbers
    can u tell me the code for this!
    thanks
    Last edited by annu000sharma; April 24th, 2010 at 10:53 PM.

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: visual basic program

    Well, probably set up a loop, with an accumulator for the total, and then add the numbers that you want to use, and skip the others
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: visual basic program

    Definitely a for loop. Natural numbers are all numbers which are not fractional.
    Like this:
    For i=1 To 100: sum=sum+1: Next
    Surely you have to declare the variables and do some work around like using a form and putting a button on and using a textbox to output the value.
    Get your hands on, show what you did and you'll sure get more help here.

  4. #4
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: visual basic program

    Quote Originally Posted by WoF View Post
    Definitely a for loop. Natural numbers are all numbers which are not fractional.
    Like this:
    For i=1 To 100: sum=sum+1: Next
    Surely you have to declare the variables and do some work around like using a form and putting a button on and using a textbox to output the value.
    Get your hands on, show what you did and you'll sure get more help here.
    Shouldn't that be sum=sum+i
    Always use [code][/code] tags when posting code.

  5. #5
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: visual basic program

    Yeah, sorry. Mistyped that. Well spotted, DataMiser.
    For i=1 To 100: sum=sum+i: Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured