❔ Validation/If statement help
it keeps saying it is not valid no matter what.. not sure why?
52 Replies
Idk what
IsOrderValid()
does
Maybe it just returns false
and doesn't do anything
idkill send it
Well, one of those is true
Run the debugger to see which
keeps saying the same thing..
confusing since i put in what should be good
i think its somewheres in my Add button click
I'd still recommend to use the debugger and see what
order
looks like at any given time
Place a breakpoint here and there, see what's going on
Also, add braces to your ifs and elses to reduce the possibility of confusionAlso, this
If the genre is null or empty, make the genre empty
My bet is on this being the issue
The genre is never not empty
And you give the order a genre from the text input, only if it isn't null or empty
oh shit wrong code
Should be the other way around if anything, shouldn't it?
wait there is braces lol
Don't see any on your ifs and elses
no not that one
oops
nevermind, there isnt any
so its probably being weird because its just one big block ?
no braces until the if isordervalid
?
What I mean is,
is ambiguous. Did you want
or
?
That's why you should have braces
C# will interpret is a the former, by the way, always
there like this lol
That should already have fixed a whole bunch of errors
Maybe even ones you didn't know of
But this is still interesting
The order will have a genre, an album name, and an artist name, only if initially the genre is not empty or null
Do you have something in your
Order()
that makes genre
not empty or null by default?
If not, then it will always be empty or null
And your order will never have the three properties mentionedno; or i dont think so at least
Then...
this will always trigger
this will never trigger
And your validator checks them
So the validation will always fail
ooh that makes sense. technically always empty
Because the genre, the artist, and the album will always and forever remain empty
Yep
so i should just remove that part maybe
IMHO this isn't needed. The genre will always be empty at the start, so why even check if it's empty?
Yeah
Just leave the three lines you have in the else
Order order = new Order();
order.genre = cboGenres.SelectedText;
order.albumName = txtAlbumName.Text;
order.artistName = txtArtistName.Text;
just like this
right?
noo still messed up
Now, make sure the double actually gets parsed correctly
That'd be my guess
it is though no?
Idk
Run the debugger and see
quantity is int and p[rice is decimal
let me try again.. i just tried and it didnt work
Aight, see if they get parsed correctly
The decimal in particular
Since, depending on the current culture, the decimal separator could be
.
or it could be ,
nope
, only works
im actually so confused cause this all seems like it should work but isnt
Idk, run the debugger, place some breakpoints, see where exactly does the validation fail
or fuck it, i lose little bit of marks for no validation
everything else is good looll
make a breakpoint here
then try again
then send a screenshot of full Visual studio
in the bottom you can see that genre is empty
yes, i just noticed
and i did select one as well
but it is empty
i chose hip hop but it shows as empty
Where do you set this genre?
order.genre = cboGenres.SelectedText;
i have this in add order
string[] genres = { "Blues", "Country", "Hip Hop", "Easy Listening", "Rock", "Pop" };
List<Order> orders = new List<Order>();
and this on top of code
im not to familair with winforms, can you create a breakpoint here
then select something in your app and try again..
might have to change .SelectedText to .Text or .Value or so
yes i changed to .text!
does that mean it works now?
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.