Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

I have a overstock error Help Please

menceconmencecon Posts: 8Member
The error is

An unhandled exception of type 'System.StackOverflowException' occurred in system.windows.forms.dll


Fatal stack overflow error.
The program '[4016] calulater.exe' has exited with code 0 (0x0).

dose anyone know how to solve this Error.


~mencecon

Comments

  • rlcrlc Posts: 448Member
    Usually this is caused by an infinite loop of some sort, specifically 'While' loops which do not have or reach a termination condition.

    ~rlc
  • menceconmencecon Posts: 8Member
    I still don't understand. Here's my code. you can try to run it, and if you get the error, tell me how to fix it.
    [Code]
    Public Class Calculator
    Inherits System.Windows.Forms.Form
    '#Region Info won't fit. If you need it tell me and I'll send it alone
    Dim c As New Calculator
    Dim opcode As String
    Dim flag As Integer = 0
    Dim flag1 As Integer = 0
    Public Enum Mode
    NumberMode
    OpMode
    EqTo
    End Enum
    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    c.getMode() = Mode.NumberMode
    c.getMode1() = Nothing
    c.firstOperand() = Nothing
    txtDisplay.Text = 0
    flag = 0
    End Sub
    Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click, btnMinus.Click, btnMultiply.Click, btnDivide.Click
    If flag = 0 Then
    txtDisplay.Text = c.firstOperand()
    flag = 1
    Else
    Call calc()
    End If
    opcode = sender.text
    c.getMode() = Mode.OpMode
    c.getMode1() = Mode.OpMode
    End Sub
    Private Sub btnSqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSqrt.Click
    If txtDisplay.Text = "" Then
    MsgBox("Enter a number")
    Else
    txtDisplay.Text = c.root(CDec(txtDisplay.Text))
    If IsNumeric(txtDisplay.Text) Then
    If c.getMode1() = Mode.NumberMode Or c.getMode1() = Mode.EqTo Or c.getMode1() = Nothing Then
    c.firstOperand() = CDec(txtDisplay.Text)
    Else
    c.secondOperand() = CDec(txtDisplay.Text)
    End If
    Else
    c.getMode1() = Nothing
    End If
    End If
    End Sub
    Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click
    If txtDisplay.Text = "" Then
    MsgBox("Enter a number")
    Else
    txtDisplay.Text = c.log(CDec(txtDisplay.Text))
    If IsNumeric(txtDisplay.Text) Then
    If c.getMode1() = Mode.NumberMode Or c.getMode1() = Mode.EqTo Or c.getMode1() = Nothing Then
    c.firstOperand() = CDec(txtDisplay.Text)
    End If
    c.getMode1() = Nothing
    End If
    End If
    End Sub
    Private Sub btnNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click, btn3.Click, btn2.Click, btn1.Click, btn6.Click, btn5.Click, btn4.Click, btn9.Click, btn8.Click, btn7.Click
    If c.getMode1() = Nothing Then
    If flag1 = 1 Then
    txtDisplay.Text = "0." + sender.tag
    flag1 = 0
    Else
    txtDisplay.Text = sender.tag
    End If
    c.firstOperand() = CDec(txtDisplay.Text)
    c.getMode() = Mode.NumberMode
    c.getMode1() = Mode.NumberMode
    ElseIf c.getMode1() = Mode.NumberMode Then
    If flag1 = 1 Then
    txtDisplay.Text = txtDisplay.Text + "." + sender.tag
    flag1 = 0
    Else
    txtDisplay.Text = txtDisplay.Text + sender.tag
    End If
    c.firstOperand() = CDec(txtDisplay.Text)
    ElseIf c.getMode1() = Mode.OpMode Then
    If c.getMode = Mode.NumberMode Then
    If flag1 = 1 Then
    txtDisplay.Text = txtDisplay.Text + "." + sender.tag
    flag1 = 0
    Else
    txtDisplay.Text = txtDisplay.Text + sender.tag
    End If
    c.secondOperand() = CDec(txtDisplay.Text)
    Else
    If flag1 = 1 Then
    txtDisplay.Text = "0." + sender.tag
    flag1 = 0
    Else
    txtDisplay.Text = sender.tag
    End If
    c.getMode() = Mode.NumberMode
    c.secondOperand() = CDec(txtDisplay.Text)
    End If
    ElseIf c.getMode1() = Mode.EqTo Then
    If flag1 = 1 Then
    txtDisplay.Text = "0." + sender.tag
    flag1 = 0
    Else
    txtDisplay.Text = sender.tag
    End If
    c.firstOperand() = CDec(txtDisplay.Text)
    c.getMode() = Mode.NumberMode
    c.getMode1() = Mode.NumberMode
    flag = 0
    End If
    End Sub
    Private Sub btnEqual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEqual.Click
    Call calc()
    End Sub
    Private Sub calc()
    If c.getMode() = Mode.NumberMode Then
    c.getMode() = Mode.EqTo
    Select Case opcode
    Case "+"
    txtDisplay.Text = float(c.Add(c.firstOperand(), c.secondOperand()))
    Case "-"
    txtDisplay.Text = float(c.Subtract(c.firstOperand(), c.secondOperand()))
    Case "X"
    txtDisplay.Text = float(c.multiply(c.firstOperand(), c.secondOperand()))
    Case "/"
    txtDisplay.Text = float(c.divide(c.firstOperand(), c.secondOperand()))
    End Select

    c.getMode1() = Mode.EqTo
    c.firstOperand() = CDec(txtDisplay.Text)
    c.secondOperand() = Nothing
    End If
    End Sub
    Private Sub btnDecimal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndot.Click
    flag1 = 1
    If c.getMode1() = Nothing Then
    txtDisplay.Text = "0"
    ElseIf c.getMode1() = Mode.OpMode Then
    If c.getMode <> Mode.NumberMode Then
    txtDisplay.Text = "0"
    End If
    ElseIf c.getMode1() = Mode.EqTo Then
    txtDisplay.Text = "0"
    End If
    End Sub
    Private Sub btnSign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsign.Click
    txtDisplay.Text = -1 * CDec(txtDisplay.Text)

    If c.getMode1() = Mode.NumberMode Or c.getMode1() = Mode.EqTo Or c.getMode1() = Nothing Then
    c.firstOperand() = CDec(txtDisplay.Text)
    Else
    c.secondOperand() = CDec(txtDisplay.Text)
    End If
    End Sub
    Private Function float(ByVal parm As Decimal) As Decimal
    Dim result As String
    Dim index As Integer
    result = parm.ToString
    index = result.IndexOf(".")
    If (index <> -1 And result.Substring(index + 1, result.Length - index - 1) = "0") Then
    Return (CDec(result.Substring(0, index)))
    Else
    Return (CDec(result))
    End If
    End Function



    Private op1 As Decimal = 0
    Private op2 As Decimal = 0
    Private Shared cMode As String = Nothing
    Private Shared pMode As String = Nothing
    Public Property firstOperand() As Decimal
    Get
    Return op1
    End Get
    Set(ByVal Value As Decimal)
    op1 = Value
    End Set
    End Property
    Public Property secondOperand() As Decimal
    Get
    Return op2
    End Get
    Set(ByVal Value As Decimal)
    op2 = Value
    End Set
    End Property
    Public Property getMode() As String
    Get
    Return cMode
    End Get
    Set(ByVal Value As String)
    cMode = Value
    End Set
    End Property
    Public Property getMode1() As String
    Get
    Return pMode
    End Get
    Set(ByVal Value As String)
    pMode = Value
    End Set
    End Property
    Public Function Add(ByVal first As Decimal, ByVal second As Decimal)
    Dim result As Decimal
    result = first + second
    Return result
    End Function
    Public Function Subtract(ByVal first As Decimal, ByVal second As Decimal)
    Dim result As Decimal
    result = first - second
    Return result
    End Function
    Public Function multiply(ByVal first As Decimal, ByVal second As Decimal)
    Dim result As Decimal
    result = first * second
    Return result
    End Function
    Public Function divide(ByVal first As Decimal, ByVal second As Decimal)
    Dim result As Decimal
    result = first / second
    Return result
    End Function
    Public Function root(ByVal first As Decimal)
    Dim result As String
    If first < 0 Then
    Return "Invalid Input"
    Else
    Return System.Math.Sqrt(first)
    End If
    End Function
    Public Function log(ByVal first As Decimal)
    Dim result As Decimal
    If first < 0 Then
    Return "Invalid Input"
    Else
    Return System.Math.Log(first)
    End If
    End Function
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

    End Sub
    Private Sub btnNumber_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumber.Click

    End Sub
    End Class
    [/Code]

    Please try to figure out how to fix it. It says that "An unhandled exception of type 'System.StackOverflowException' occurred in system.windows.forms.dll" Can you help me figure out how to get it to cooperate?



    ~Mencecon

  • rlcrlc Posts: 448Member
    Figure out where in the code it is breaking and I will look at it.

    I will recommend that you use error catching in your code... Like so

    [code]SomeFunction()
    Try
    ' some code
    Catch Ex as exception
    'do whatever with error , write to log pop-up
    msgbox(ex.message)
    End Try
    End Function[/code]
    This will stop exceptions from crashing your app and allow you to handle them.

    Also to find out where in your code the exception is happening use the debugger. You can set 'breakpoints' by clicking the gray vertical line to the left of your coding area where there is executable code, you will see a red dot. Click the run debug button in toolbar and it will open in debug mode. Once your code gets to a breakpoint you can step line by line through the execution.


    ~rlc
  • menceconmencecon Posts: 8Member
    Lame's terms, Please?!?
  • rlcrlc Posts: 448Member
    : Figure out where in the code it is breaking and I will look at it.
    :
    : I will recommend that you use error catching in your code... Like so
    :
    : [code]SomeFunction()
    : Try
    : ' some code
    : Catch Ex as exception
    : 'do whatever with error , write to log pop-up
    : msgbox(ex.message)
    : End Try
    : End Function[/code]
    : This will stop exceptions from crashing your app and allow you to handle them.
    :
    : Also to find out where in your code the exception is happening use the debugger. You can set 'breakpoints' by clicking the gray vertical line to the left of your coding area where there is executable code, you will see a red dot. Click the run debug button in toolbar and it will open in debug mode. Once your code gets to a breakpoint you can step line by line through the execution.
    :
    :
    : ~rlc
    :

    find out which line in your code causes the error... You can do this through the debugger, and using try cacth statements in your ocode. Since it didn't look like you had many loops I would say it is a type conversion issue somewhere.
Sign In or Register to comment.