C
C#

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

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

Hhugheselite11/21/2023
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 https://paste.mod.gg/xpjzxfmjjeik/0 else function is right at the bottom I feel i'm being real stupid here
TThinker11/21/2023
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
Hhugheselite11/21/2023
the one at the very bottom { ErrorHandlingWindow.Text = InvalidCommandMessage; return; }
TThinker11/21/2023
Only situation in which that could execute is if none of the above cases succeeded
Hhugheselite11/21/2023
I realised this when I'd implemented nearly everything haha 😦
TThinker11/21/2023
Have you tried debugging the code? The most obvious answer would be that CommandSplit[0] is not what you're expecting it to be
Hhugheselite11/21/2023
it's still executing even if a condition is working for example
Hhugheselite11/21/2023
No description
Hhugheselite11/21/2023
even though the circle was drawn on th bitmap fine, still outputs the error message
ZZacharyPatten11/21/2023
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
Hhugheselite11/21/2023
i've posted the full code in the thread 🙂
ZZacharyPatten11/21/2023
that isn't the full code
Hhugheselite11/21/2023
this one
ZZacharyPatten11/21/2023
we cannot run that
TThinker11/21/2023
that's one file
Hhugheselite11/21/2023
ohh got you okay sure yes my bad one moment https://bitbucket.org/110794-main-workspace/ase-component-1/src/master/ Could you please let me know if this is downloadable? thank you
ZZacharyPatten11/21/2023
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
ZZacharyPatten11/21/2023
No description
ZZacharyPatten11/21/2023
sorry I know that is low quality of a screenshot, but hopefully you see can see where the two bindings are
Hhugheselite11/21/2023
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
ZZacharyPatten11/21/2023
I saw this and I pretty much immediately knew the issue:
No description
Hhugheselite11/21/2023
awesome good to know going forward
ZZacharyPatten11/21/2023
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
Hhugheselite11/21/2023
right on, well thank you again for you time, have a great day !close
AAccord11/21/2023
Closed!

Looking for more? Join the community!

C
C#

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

Join Server
Want results from more Discord servers?
Add your server
Recommended Posts
Maui adb additional parametersI need to test a Maui applicaiton on a physical android device. The app recorded a error, to see whHow to let compiler know that List is not null?Hi community! I have the following extension method:, which checks if the source is not null and if✅ How to Fix MSB6006 yasm.exe exited with code -1073741515 on Cosmos Kernel✅ Issue during pushing a commit to GitHub from VS CodeHi friends, I'm working on a project using `VS Code`, I used `VS Code` to clon that project from my✅ Need help understanding inheritance with constructorsI know about constructors partially (I'm used to Unity's MonoBehaviour so constructors are mostly suHow to get the data of an adapter using MQTTnetThis is the documentation: https://docs.service.sicon.eco/sicon.os/2023.19.x/adapter-protocol-smqtt Converting from a string to a generic method invocationLooking for design patterns to help solve this problem I’m having at work. The situation is that we Auto refresh inside windows formTeam , We are using windows form c#. Is there any library for auto refresh (need to few logic eve✅ Fresh Install of Windows, I'm Getting Weird Errors (NETSDK1/NU1012, and DEP0700)Anyone know what might be happening here in my Maui Blazor Hybrid projects? For the older project object reference not set to instance of object on a static method callso im trying to use an opengl binding package (Veldrid.OpenGLBinding) but, when i call any of the meWeb API model classesI'm coding a webshop using ASP.NET Core Web API for the backend and Next.js for the frontend. I'm deInvalidate JWT-Tokens on logout and password change.I have an ASP.net Web api that handles user interaction. For authentification I use JWT Tokens. I reDynamically enable/disable a route in ASP.NET 7?Is there a way to dynamically enable/disable a route in ASP.NET 7? I'd like to be able to enable/dis✅ I keep getting Error CS5001 and CS0028, how do i get rid of themin CS5001 it says Program does not contain a static "Main" method suitable for an entry point and inStruct with explicit layoutHi, I am using Wintab and I am trying to make packet struct, but I have some problem. In some situatExtending custom WPF controlWhat are my options to extend this TimePicker list element to full height that shows all items? I'm Discord.Net + MagicOnion, hehehHey! So I am working on a discord bot that I want to intergrate into a server using websockets, I fA question for my c# winforms projecthello guys, i have a question about my c# winforms project. So : I have 2 Projects the first ProjecYO I NEED HELP writing a code need advice not for u to write it for mewrite me a c# program that get 3 latters and tell if they are by the order like abc if they are backBlazor ServicesI dont know too much blazor, but I have a .cs file in a /Settings folder, in which I would like to a