Klogg Posted October 8, 2003 Posted October 8, 2003 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? Quote Take a look at my programs. Go to my web site.
*Experts* mutant Posted October 8, 2003 *Experts* Posted October 8, 2003 Does the application show you any errors and stops responding or just hangs? If there are errors tell what they are. Quote
Administrators PlausiblyDamp Posted October 8, 2003 Administrators Posted October 8, 2003 Could you show us the code in question? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Leaders dynamic_sysop Posted October 8, 2003 Leaders Posted October 8, 2003 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. Quote
Klogg Posted October 8, 2003 Author Posted October 8, 2003 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? Quote Take a look at my programs. Go to my web site.
*Experts* mutant Posted October 8, 2003 *Experts* Posted October 8, 2003 What is the code that causes it to hang? Quote
Klogg Posted October 8, 2003 Author Posted October 8, 2003 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 Quote Take a look at my programs. Go to my web site.
Klogg Posted October 8, 2003 Author Posted October 8, 2003 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. Quote Take a look at my programs. Go to my web site.
*Experts* mutant Posted October 8, 2003 *Experts* Posted October 8, 2003 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? Quote
Klogg Posted October 8, 2003 Author Posted October 8, 2003 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. Quote Take a look at my programs. Go to my web site.
*Experts* mutant Posted October 9, 2003 *Experts* Posted October 9, 2003 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. Quote
Klogg Posted October 9, 2003 Author Posted October 9, 2003 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. Quote Take a look at my programs. Go to my web site.
*Experts* mutant Posted October 9, 2003 *Experts* Posted October 9, 2003 Yes it indeed is very helpful :). Now that you know how to use it, it will help you with a lot of things like that. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.