Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Does anyone know what causes a program to stop responding? I am making a calculator application, and I changed the EqualsButton Click event subprocedure so that it would (hopefully) do the order of operations. Now when I click the equals button, it stops responding. I tried to find the error, but I couldn't. Could someone please help me figure this out?
Take a look at my programs. Go to my web site.
  • Leaders
Posted

you could encapsulate the code within a Try Catch statement, then you should be able to see what the error is ( ie: the description ) , like this...

'/// within your sub for the EqualsButton Click event...
Try
   '/// carry out your code which is falling down here.
Catch Ex As Exception
   MessageBox.Show(Ex.Message) '/// the error thats being thrown.
End Try

hope that helps you pinpoint the problem.

Posted
There is no error message. It just acts like its calculating for a while, then the cursor changes to an hourglass. If I press Ctrl+Alt+Del, then it says it's not responding. How do you put code in the forum with a white background and highlighted keywords?
Take a look at my programs. Go to my web site.
Posted

Here's my code for the EqualsButton. I found out how to format it.

 

   Private Sub EqualsButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EqualsButton.Click
       'declare local variables
       Dim sngAnswer As Single
       Dim intCount, intCount2 As Integer
       Dim blnWasMerged(30) As Boolean
       Dim blnOperationDone As Boolean
       'put last value in array
       sngInput(shrSubscript) = Val(strInput)
       'calculate multiplication and division
       Do
           If chaOperationUsed(intCount) = "*" Or chaOperationUsed(intCount) = "/" Then
               If chaOperationUsed(intCount) = "*" Then
                   sngInput(intCount + 1) = sngInput(intCount) * sngInput(intCount + 1)
                   blnWasMerged(intCount) = True
               End If
               If chaOperationUsed(intCount) = "/" Then
                   sngInput(intCount + 1) = sngInput(intCount) / sngInput(intCount + 1)
                   blnWasMerged(intCount) = True
               End If
           End If
       Loop While intCount <= 29
       'calculate addition and subtraction
       intCount = 0
       Do
           If chaOperationUsed(intCount) = "+" Or chaOperationUsed(intCount) = "-" Then
               If chaOperationUsed(intCount) = "+" Then
                   intCount2 = 1
                   blnOperationDone = False
                   'go through the numbers until it reaches the right number to add
                   Do
                       If blnWasMerged(intCount + intCount2) = False Then
                           sngInput(intCount + intCount2) = sngInput(intCount) + sngInput(intCount + intCount2)
                           blnOperationDone = True
                       End If
                       intCount2 = intCount2 + 1
                   Loop While blnOperationDone = False
               End If
               If chaOperationUsed(intCount) = "-" Then
                   intCount2 = 1
                   blnOperationDone = False
                   'go through the numbers until it reaches the right number to subtract
                   Do
                       If blnWasMerged(intCount + intCount2) = False Then
                           sngInput(intCount + intCount2) = sngInput(intCount) - sngInput(intCount + intCount2)
                           blnOperationDone = True
                       End If
                       intCount2 = intCount2 + 1
                   Loop While blnOperationDone = False
               End If
           End If
       Loop While intCount <= 29
       'show answer
       Me.ExpressionTextBox.Text = Me.ExpressionTextBox.Text & sngInput(shrSubscript)
       'clear chaOperationUsed
       intCount = 0
       Do
           chaOperationUsed(intCount) = ""
           intCount = intCount + 1
       Loop While intCount <= 29
       'reset shrSubscript and chaOperationUsed and give blnJustCalculated a value of 1
       shrSubscript = 0
       blnJustCalculated = True
   End Sub

Take a look at my programs. Go to my web site.
Posted
Did you guys think that I solved my problem, or are you just busy answering other people's questions? When I said "I found out how to format it" on my last response, I meant that I found out how to put my code up here, not that I found out what was wrong. So I still need help if you've got time.
Take a look at my programs. Go to my web site.
  • *Experts*
Posted
If the application just hangs then my guess is that it hangs on one of the loops. Did you try stepping through the code to see at what point in the method it hangs?
Posted
No, I don't know how to step through the code. I'm a beginning programmer, so I don't know how those debugging tools work. Could you explain it to me? I would use the help files, but they aren't very well-made and I don't understand them.
Take a look at my programs. Go to my web site.
  • *Experts*
Posted
You can start stepping through code by usnig Step Into command from the Debug menu. Or pressing F11. But first set a breakpoint on the first line of your sub that handles the button, you can do that by clicking on the gray area just left of the code editor. Then start your program. When the program reaches the breakpoint, the execution will stop. Then keep pressing F11 to step through the code.
Posted
Yay! I found the problem. It's a stupid one. I forgot to make intCount increase in at least one of the loops. Thanks for all your help. That stepping tool is really helpful. I don't know why my textbook doesn't tell me about it. Now I can see what all the variables are while the program is running without having to make temporary text boxes to show them.
Take a look at my programs. Go to my web site.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...