Results 1 to 6 of 6

Thread: Request for help

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2012
    Posts
    6

    Unhappy Request for help

    I am working on an assignment due this Friday ( my teacher has told that he can not help me ) and have some sort of logic error. I am trying to create a very basic program that ask the user to enter a positive integer value and give back the sum of 1 to the defined value. example --> user enters 10 & the program gives the answer of 55 ( the sum of all integer between 1 & 10)

    Code:
    
            Dim intCounter As Integer
            Dim intNumber As Integer
            Dim intNumberSum As Integer
            Dim Numeric As Integer = 1
            Dim strInputBox As String
    
            strInputBox = InputBox("Please enter a positive integer value", "Input needed")
    
            intNumber = CInt(strInputBox)
    
            If strInputBox < 1 Then
                MessageBox.Show("Value can not be less then 1")
    
    
    
            End If
    
            Do While intCounter < intNumber
                intNumberSum = intCounter + 1
                intCounter += 1
                Numeric = +1
     ' last idea tried to get the logic work.  I don't think this line is really needed. My line of thinking is the counter should be used to get the new value and add one to it
    
               Loop
    
            MessageBox.Show("The sum of the numbers 1 through " & strInputBox & " is " & intNumberSum & ".")
    
        End Sub

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Request for help

    intNumberSum = intCounter + 1

    Just think about what this line actually does for 5 seconds, then think about what it should do. Then read my signature!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3
    Hyperactive Member
    Join Date
    Jan 2012
    Location
    Florida
    Posts
    285

    Re: Request for help

    I'll give you a hint.....

    vb.net Code:
    1. Public Function SumOfIntegers(ByVal int As Integer) As Integer
    2.         Dim sum As New Integer
    3.         For i = 1 To int
    4.             'Code Goes Here...
    5.         Next
    6.         Return sum
    7.     End Function

    Now the real question is, how can I make it so I can enter a value of over 65535 and not get an error.....
    Last edited by thebuffalo; Sep 24th, 2012 at 01:41 PM.

  4. #4

    Thread Starter
    New Member
    Join Date
    Sep 2012
    Posts
    6

    Unhappy Re: Request for help

    Your hint is a bit over my head as this my first time dealing with programming. Would you please break it down a bit and add a line or two about why it is done that way.


    Quote Originally Posted by thebuffalo View Post
    I'll give you a hint.....

    vb.net Code:
    1. Public Function SumOfIntegers(ByVal int As Integer) As Integer
    2.         Dim sum As New Integer
    3.         For i = 1 To int
    4.             'Code Goes Here...
    5.         Next
    6.         Return sum
    7.     End Function

    Now the real question is, how can I make it so I can enter a value of over 65535 and not get an error.....

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2012
    Posts
    6

    Re: Request for help

    as I am very new to programming and having a learning disability I would to like to ask for a bit more detail as this is rocket science to me.

  6. #6
    Hyperactive Member
    Join Date
    Jan 2012
    Location
    Florida
    Posts
    285

    Re: Request for help

    vb.net Code:
    1. Public Function SumOfIntegers(ByVal int As Integer) As Integer 'You do it this way because a function returns a value, your answer, and you can easily put your integer from the textbox into the function.
    2.         Dim sum As New Integer ' This is your total sum
    3.         For i = 1 To int ' For every number from 1 to your integer, i = that number, this is a loop that will happen for each "i"
    4.             'This is the only line of code you need, think about your question.... you take 1, then add 2, then add 3, the sum would be the previous number before adding the next number which would be "i"
    5.             sum += i
    6.         Next
    7.         Return sum ' This returns your final value
    8.     End Function
    9.  
    10. ' To call the function you will have to do this... Most Likely in a button.click event that will be below your text box.
    11. Textbox1.Text = SumOfIntegers(Textbox1.Text)

Tags for this Thread

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