Code Question (C related)

Support, Discussion, Reviews
Post Reply
User avatar
Kylere
Way too much time!
Way too much time!
Posts: 3354
Joined: July 3, 2002, 6:26 pm
Location: Flint, Michigan

Code Question (C related)

Post by Kylere »

I have (with the leading less than and percent symbol ) ( C# language)

Code: Select all

 if(( null == this.Request.Params["stagefilter"] ? "" : this.stagefilter.SelectedItem.Value.Trim()).Equals("Exhibit Hall Stage")){ % >
I want to make it "Exhibit Hall Stage, Ballroom Stage" ( as in either or)

Anyone know the proper syntax?


Nevermind made the neat little if, else a if, or, else
She Dreams in Digital
\"Led Zeppelin taught an entire generation of young men how to make love, if they just listen\"- Michael Reed(2005)
User avatar
Sylvus
Super Poster!
Super Poster!
Posts: 7033
Joined: July 10, 2002, 11:10 am
Gender: Male
XBL Gamertag: mp72
Location: A², MI
Contact:

Post by Sylvus »

I have to admit that I've never even looked at C# code, but it appears similar enough to Java...

First off, I'd break that ternary statement out of there. Declare a string variable, assign the value of the ternary statement to it. If only for readability's sake.

I don't know the proper syntax for String declaration in C#, but a quick search leads me to believe that you'd want something along the lines of

Code: Select all

string stageFilter = ( null == this.Request.Params["stagefilter"] ? "" : this.stagefilter.SelectedItem.Value.Trim());
Then it sounds like you want to compare that value, that you've received from a form or somesuch, to the strings "Exhibit Hall Stage" and "Ballroom Stage" and, if the value that has been submitted matches either string, perform the same activity?

Code: Select all

if(stageFilter.Equals("Exhibit Hall Stage") || stageFilter.Equals("Ballroom Stage")) { % >
So the whole thing would look like

Code: Select all

string stageFilter = ( null == this.Request.Params["stagefilter"] ? "" : this.stagefilter.SelectedItem.Value.Trim());
if(stageFilter.Equals("Exhibit Hall Stage") || stageFilter.Equals("Ballroom Stage")) { % >
There might be some minor tweaks needed in there, but for the most part that conditional-OR should work.
"It's like these guys take pride in being ignorant." - Barack Obama

Go Blue!
User avatar
Kylere
Way too much time!
Way too much time!
Posts: 3354
Joined: July 3, 2002, 6:26 pm
Location: Flint, Michigan

Post by Kylere »

Thanks Sylvus!

That does work, yeah I pull from an access db the define for the stage name, and compare it. It is for a generated pdf of the schedule and it does an else to remove days from the date count so that;

Day 1 Stage 1 is the 1st
Day 2 Stage 1 is the 2nd
Day 1 Stage 2 is the 1st again

Because it processes it straight from a schedule table, with day ends adding dates. I have not had a chance to redo that table and the code to add a second stage field to simplify this all, since I also have to change the DB they use to update the web. I had planned on doing it as a season end code update.

But then the company got busy and we have 7 diff cities in one weekend, and three of them have 2nd stages and one even has a third. So it was a crunch. Warning fellow geeks, I started this giving advice to a friend, stepped in once to help with a problem, covered a DB issue once, and now I have a 20 hour plus a week side job that I did not intend to have.
She Dreams in Digital
\"Led Zeppelin taught an entire generation of young men how to make love, if they just listen\"- Michael Reed(2005)
Post Reply