C
C#2y ago
SAFE

❔ Validation/If statement help

it keeps saying it is not valid no matter what.. not sure why?
52 Replies
Angius
Angius2y ago
Idk what IsOrderValid() does Maybe it just returns false and doesn't do anything idk
SAFE
SAFEOP2y ago
ill send it
SAFE
SAFEOP2y ago
Angius
Angius2y ago
Well, one of those is true Run the debugger to see which
SAFE
SAFEOP2y ago
keeps saying the same thing.. confusing since i put in what should be good i think its somewheres in my Add button click
Angius
Angius2y ago
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 confusion
Angius
Angius2y ago
Also, this
Angius
Angius2y ago
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
SAFE
SAFEOP2y ago
oh shit wrong code
Angius
Angius2y ago
Should be the other way around if anything, shouldn't it?
SAFE
SAFEOP2y ago
wait there is braces lol
Angius
Angius2y ago
Don't see any on your ifs and elses
SAFE
SAFEOP2y ago
SAFE
SAFEOP2y ago
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
Angius
Angius2y ago
? What I mean is,
if (something)
Stuff();
MoreStuff();
if (something)
Stuff();
MoreStuff();
is ambiguous. Did you want
if (something)
{
Stuff();
}
MoreStuff();
if (something)
{
Stuff();
}
MoreStuff();
or
if (something)
{
Stuff();
MoreStuff();
}
if (something)
{
Stuff();
MoreStuff();
}
? That's why you should have braces C# will interpret is a the former, by the way, always
SAFE
SAFEOP2y ago
SAFE
SAFEOP2y ago
there like this lol
Angius
Angius2y ago
That should already have fixed a whole bunch of errors Maybe even ones you didn't know of
Angius
Angius2y ago
But this is still interesting
Angius
Angius2y ago
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 mentioned
SAFE
SAFEOP2y ago
no; or i dont think so at least
Angius
Angius2y ago
Then...
Angius
Angius2y ago
this will always trigger
Angius
Angius2y ago
this will never trigger
Angius
Angius2y ago
And your validator checks them
Angius
Angius2y ago
So the validation will always fail
SAFE
SAFEOP2y ago
ooh that makes sense. technically always empty
Angius
Angius2y ago
Because the genre, the artist, and the album will always and forever remain empty Yep
SAFE
SAFEOP2y ago
so i should just remove that part maybe
Angius
Angius2y ago
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
SAFE
SAFEOP2y ago
Order order = new Order(); order.genre = cboGenres.SelectedText; order.albumName = txtAlbumName.Text; order.artistName = txtArtistName.Text; just like this right? noo still messed up
Angius
Angius2y ago
Now, make sure the double actually gets parsed correctly That'd be my guess
SAFE
SAFEOP2y ago
it is though no?
Angius
Angius2y ago
Idk Run the debugger and see
SAFE
SAFEOP2y ago
quantity is int and p[rice is decimal let me try again.. i just tried and it didnt work
Angius
Angius2y ago
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 ,
SAFE
SAFEOP2y ago
nope , only works im actually so confused cause this all seems like it should work but isnt
Angius
Angius2y ago
Idk, run the debugger, place some breakpoints, see where exactly does the validation fail
SAFE
SAFEOP2y ago
or fuck it, i lose little bit of marks for no validation everything else is good looll
ACiDCA7
ACiDCA72y ago
make a breakpoint here
ACiDCA7
ACiDCA72y ago
then try again then send a screenshot of full Visual studio
SAFE
SAFEOP2y ago
ACiDCA7
ACiDCA72y ago
in the bottom you can see that genre is empty
SAFE
SAFEOP2y ago
yes, i just noticed and i did select one as well but it is empty i chose hip hop but it shows as empty
Angius
Angius2y ago
Where do you set this genre?
SAFE
SAFEOP2y ago
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
ACiDCA7
ACiDCA72y ago
im not to familair with winforms, can you create a breakpoint here
ACiDCA7
ACiDCA72y ago
ACiDCA7
ACiDCA72y ago
then select something in your app and try again.. might have to change .SelectedText to .Text or .Value or so
SAFE
SAFEOP2y ago
yes i changed to .text!
ACiDCA7
ACiDCA72y ago
does that mean it works now?
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server