Results 1 to 23 of 23

Thread: [RESOLVED] Going beyond the assignment

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2012
    Location
    Florida
    Posts
    285

    Resolved [RESOLVED] Going beyond the assignment

    http://www.vbforums.com/showthread.p...89#post4243389

    This thread got me working on a self-project.... Why can't I do this function with any number greater than 65535

    vb.net Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    4.         TextBox1.Text = CStr(SumOfIntegers(CInt(TextBox1.Text)))
    5.     End Sub
    6.     Public Function SumOfIntegers(ByVal int As Integer) As Integer
    7.         Dim nint As New Integer
    8.         Dim sum As New Integer
    9.         For i = 1 To int
    10.             sum += i
    11.         Next
    12.         Return sum
    13.     End Function
    14. End Class

    Arithmetic operation resulted in an overflow.

    vb .net Code:
    1. Public Function SumOfIntegers(ByVal int As Integer) As Integer
    2.         Dim nint As New Integer
    3.         Dim sum As New Integer
    4.         If int > 65535 Then
    5.             For i = 1 To 65535
    6.                 sum += i
    7.             Next
    8.             For i = 65536 To int
    9.                 sum += i
    10.             Next
    11.         Else
    12.             For i = 1 To int
    13.                 sum += i
    14.             Next
    15.         End If
    16.         Return sum
    17.     End Function

    This does not work either.
    Last edited by thebuffalo; Sep 24th, 2012 at 02:11 PM.

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