Nested if statements
-
Good afternoon. I was wondering if there is a more efficient way to write this code:
//Resets the browser to the previous page when an item is deleted.
if (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1)
{
WebBrowser1.GoBack();
}
else if (cboWS.SelectedIndex == -1 && inttmpWS != -1)
{
WebBrowser1.GoBack();
}
else if (cboFolder.SelectedIndex == -1 && inttmpF != -1)
{
WebBrowser1.GoBack();
}I want to call the WebBrowser1.GoBack(); once if possible. Thank you, WHEELS
-
Good afternoon. I was wondering if there is a more efficient way to write this code:
//Resets the browser to the previous page when an item is deleted.
if (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1)
{
WebBrowser1.GoBack();
}
else if (cboWS.SelectedIndex == -1 && inttmpWS != -1)
{
WebBrowser1.GoBack();
}
else if (cboFolder.SelectedIndex == -1 && inttmpF != -1)
{
WebBrowser1.GoBack();
}I want to call the WebBrowser1.GoBack(); once if possible. Thank you, WHEELS
Wheels012 wrote:
I want to call the WebBrowser1.GoBack(); once if possible.
Do nested If
if (cboSP_Site.SelectedIndex == -1)
{
if (inttmSP != -1 || inttmpWS != -1 || inttmpF != -1)
WebBrowser1.GoBack();
}I hope i did it correctly
-
Good afternoon. I was wondering if there is a more efficient way to write this code:
//Resets the browser to the previous page when an item is deleted.
if (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1)
{
WebBrowser1.GoBack();
}
else if (cboWS.SelectedIndex == -1 && inttmpWS != -1)
{
WebBrowser1.GoBack();
}
else if (cboFolder.SelectedIndex == -1 && inttmpF != -1)
{
WebBrowser1.GoBack();
}I want to call the WebBrowser1.GoBack(); once if possible. Thank you, WHEELS
there are many ways to get what you want, here is one:
if ((cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
(cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
(cboFolder.SelectedIndex == -1 && inttmpF != -1)) {
WebBrowser1.GoBack();
}and another one:
bool goBack=false;
if (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) goBack=true;
else if (cboWS.SelectedIndex == -1 && inttmpWS != -1) goBack=true;
else if (cboFolder.SelectedIndex == -1 && inttmpF != -1)) goBack=true;
if (goBack) WebBrowser1.GoBack();BTW: here the "else" keywords are optional :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
modified on Monday, November 30, 2009 4:23 PM
-
Wheels012 wrote:
I want to call the WebBrowser1.GoBack(); once if possible.
Do nested If
if (cboSP_Site.SelectedIndex == -1)
{
if (inttmSP != -1 || inttmpWS != -1 || inttmpF != -1)
WebBrowser1.GoBack();
}I hope i did it correctly
Saksida Bojan wrote:
I hope i did it correctly
Not really. Every letter counts here. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
there are many ways to get what you want, here is one:
if ((cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
(cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
(cboFolder.SelectedIndex == -1 && inttmpF != -1)) {
WebBrowser1.GoBack();
}and another one:
bool goBack=false;
if (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) goBack=true;
else if (cboWS.SelectedIndex == -1 && inttmpWS != -1) goBack=true;
else if (cboFolder.SelectedIndex == -1 && inttmpF != -1)) goBack=true;
if (goBack) WebBrowser1.GoBack();BTW: here the "else" keywords are optional :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
modified on Monday, November 30, 2009 4:23 PM
-
Thank you Luc.
if ((cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
(cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
(cboFolder.SelectedIndex == -1 && inttmpF != -1)) {
WebBrowser1.GoBack();
}Is what I am looking for. A little slow today. WHEELS
5 years from now, you'll probably be scratching your head over what this code does. At the risk of being chastised for writing more code, I suggest you amend the code to:
bool itemDeleted = (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
(cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
(cboFolder.SelectedIndex == -1 && inttmpF != -1);
if (itemDeleted) {
WebBrowser1.GoBack();
}/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
5 years from now, you'll probably be scratching your head over what this code does. At the risk of being chastised for writing more code, I suggest you amend the code to:
bool itemDeleted = (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
(cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
(cboFolder.SelectedIndex == -1 && inttmpF != -1);
if (itemDeleted) {
WebBrowser1.GoBack();
}/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
I agree.
-
I agree.
that's why I offered some alternatives, you pick whichever you like most. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
-
5 years from now, you'll probably be scratching your head over what this code does. At the risk of being chastised for writing more code, I suggest you amend the code to:
bool itemDeleted = (cboSP_Site.SelectedIndex == -1 && inttmpSP != -1) ||
(cboWS.SelectedIndex == -1 && inttmpWS != -1) ||
(cboFolder.SelectedIndex == -1 && inttmpF != -1);
if (itemDeleted) {
WebBrowser1.GoBack();
}/ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com