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:
Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click TextBox1.Text = CStr(SumOfIntegers(CInt(TextBox1.Text))) End Sub Public Function SumOfIntegers(ByVal int As Integer) As Integer Dim nint As New Integer Dim sum As New Integer For i = 1 To int sum += i Next Return sum End Function End Class
Arithmetic operation resulted in an overflow.
vb .net Code:
Public Function SumOfIntegers(ByVal int As Integer) As Integer Dim nint As New Integer Dim sum As New Integer If int > 65535 Then For i = 1 To 65535 sum += i Next For i = 65536 To int sum += i Next Else For i = 1 To int sum += i Next End If Return sum End Function
This does not work either.




Reply With Quote