C
C#13mo ago
hugheselite

✅ else statement executing regardless of whether I want it to or not, windows form app

I've created a simple windows form app to create shapes on a bitmap, I have a function that gives an error if the user inputs an invalid input. it's currently executing even if the input is valid.. I'm pretty sure it's a simple fix would just appreciate an extra pair of eyes on this one lol
28 Replies
hugheselite
hugheseliteOP13mo ago
BlazeBin - xpjzxfmjjeik
A tool for sharing your source code with the world!
hugheselite
hugheseliteOP13mo ago
else function is right at the bottom I feel i'm being real stupid here
Thinker
Thinker13mo ago
There are a lot of else cases here, which one do you mean? Also this would be an ideal situation to use a switch statement
hugheselite
hugheseliteOP13mo ago
the one at the very bottom { ErrorHandlingWindow.Text = InvalidCommandMessage; return; }
Thinker
Thinker13mo ago
Only situation in which that could execute is if none of the above cases succeeded
hugheselite
hugheseliteOP13mo ago
I realised this when I'd implemented nearly everything haha 😦
Thinker
Thinker13mo ago
Have you tried debugging the code? The most obvious answer would be that CommandSplit[0] is not what you're expecting it to be
hugheselite
hugheseliteOP13mo ago
it's still executing even if a condition is working for example
hugheselite
hugheseliteOP13mo ago
No description
hugheselite
hugheseliteOP13mo ago
even though the circle was drawn on th bitmap fine, still outputs the error message
ZacharyPatten
ZacharyPatten13mo ago
if you share the full code (preferably with a github repo link) then we could help you. but without the full code it is hard for us to help other than encouraging you to put breakpoints and debug
hugheselite
hugheseliteOP13mo ago
i've posted the full code in the thread 🙂
ZacharyPatten
ZacharyPatten13mo ago
that isn't the full code
hugheselite
hugheseliteOP13mo ago
this one
ZacharyPatten
ZacharyPatten13mo ago
we cannot run that
Thinker
Thinker13mo ago
that's one file
hugheselite
hugheseliteOP13mo ago
ohh got you okay sure yes my bad one moment
hugheselite
hugheseliteOP13mo ago
Could you please let me know if this is downloadable? thank you
ZacharyPatten
ZacharyPatten13mo ago
it is. I tested "circle 25" and it seemed to work. what input are you testing that is still hitting the else that you don't want it to? o wait I was testing the button when you press Enter is when it is running the code twice One moment SingleCommandLine.KeyDown += singleCommandLine_KeyDown_1; SingleCommandLine.KeyDown += singleCommandLine_KeyDown_1; you are binding your event handler twice so every time you press enter it is currently runnign the code twice in your Form1.Designer.cs class is where that is happening one on line 165 and one on line 52 you clear the text box during the code, so if you run the code twice, the first run will clear the text box so that the second time it runs it will be blank and therefore cause the error you are seeing so in short... you should remove one of the double event bindings you should only have one binding for that event handler
ZacharyPatten
ZacharyPatten13mo ago
No description
ZacharyPatten
ZacharyPatten13mo ago
sorry I know that is low quality of a screenshot, but hopefully you see can see where the two bindings are
hugheselite
hugheseliteOP13mo ago
There is currently an IT guy installing a new router in my office In about 20 mins I'm going to go an edit my code Your logic sounds 100% correct here to me so thank you vm for your time You are completely correct and fixed the issue If you don't mind sharing how you went about figuring out the problem? that'd be wonderful
ZacharyPatten
ZacharyPatten13mo ago
I saw this and I pretty much immediately knew the issue:
No description
hugheselite
hugheseliteOP13mo ago
awesome good to know going forward
ZacharyPatten
ZacharyPatten13mo ago
there are times when you do want mutiple UI elements to bind to the same handler... but it is not typical for KeyDown events specifically
hugheselite
hugheseliteOP13mo ago
right on, well thank you again for you time, have a great day !close
Accord
Accord13mo ago
Closed!
Want results from more Discord servers?
Add your server