?
Solved

When is End If not necessary?

Posted on 2005-04-27
9
Medium Priority
?
244 Views
Last Modified: 2012-06-27
I have the following code that works without the end if statements. Why does it work without it, and should I have it in anyway? It's in the middle of a different loop.

If rstemp("SomeNumber")="1" then Response.write "Some Message 1"
If rstemp("SomeNumber")="2" then Response.write "Some Message 2"
If rstemp("SomeNumber")="3" then Response.write "Some Message 3"
If rstemp("SomeNumber")="4" then Response.write "Some Message 3"
If rstemp("SomeNumber")="5" then Response.write "Some Message 5"
0
Comment
Question by:net_susan
9 Comments
 
LVL 97

Accepted Solution

by:
Lee W, MVP earned 1000 total points
ID: 13878183


End if is not necessary if your "then" instructions are on the same line:

For example - NOT Necessary:
If rstemp("SomeNumber")="1" then Response.write "Some Message 1"

For example - NECESSARY:
If rstemp("SomeNumber")="1" then
    Response.write "Some Message 1"
End If
0
 
LVL 97

Assisted Solution

by:Lee W, MVP
Lee W, MVP earned 1000 total points
ID: 13878193
In fact, if you put an "End IF" after something like this:
If rstemp("SomeNumber")="1" then Response.write "Some Message 1"
I THINK you would get an error message.
0
 
LVL 10

Assisted Solution

by:ThaSmartUno
ThaSmartUno earned 100 total points
ID: 13878671
similarly ... if you use an if like this it is necessary
blah blah blah <% If IsRegistered Then %> Hey you are registered! <% End If %> blah blah blah

however if you do
blah blah blah <% If IsRegistered Then Response.Write "Hey you are registered!" %> blah blah blah

End if is not needed


0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 46

Assisted Solution

by:fritz_the_blank
fritz_the_blank earned 700 total points
ID: 13881147
Of course, I am old man grumpus and always want an END IF regardless of whether or not it is required. Should you want it all on one line, I think that you can do:

If something then : 'your code ; end if


ftB
0
 
LVL 46

Assisted Solution

by:fritz_the_blank
fritz_the_blank earned 700 total points
ID: 13881165
Select Case rstemp("SomeNumber")
      Case "1"
            Response.write "Some Message 1"
      Case "2"
            Response.write "Some Message 2"
      Case "3"
            Response.write "Some Message 3"
      Case "4"
            Response.write "Some Message 4"
      Case "5"
            Response.write "Some Message 5"
      Case Else
            Response.write("No number!")
End Select
0
 
LVL 2

Assisted Solution

by:Coolhand2120
Coolhand2120 earned 200 total points
ID: 13882889
I'm with old man fritz, end if is our friend, so is tabbing your formating.  It's not just pretty, it helps narrow down errors and makes it easier for other programmers to read your code.

If you're intent on making big bunches of single line code, you can always use the EXECUTE function in ASP.  Lots of fun there:

str = "IF 1>0 THEN:RESPONSE.WRITE ""WOOHOO LOGIC IS WORTHLESS!"":ELSE:RESPONSE.WRITE ""LOOKS LIKE EUCLID WAS RIGHT!"":END IF:RESPONSE.WRITE ""YOU CAN GO ON FOREVER"":"

execute(str)

: (colon) is the same as a real carrage return.


-Coolhand2120

Fritz is the all knowing oracle

0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 13885232
Oops! I wrote:

If something then : 'your code ; end if

Instead of:

If something then : 'your code : end if

>>Fritz is the all knowing oracle<<

Hardly! Many people don't know this, but I learned ASP here. My first question?  http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_10752001.html


;-)

FtB
0
 
LVL 1

Author Comment

by:net_susan
ID: 13918361
Thanks!  And wow, Fritz, that's nice to know you started here.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 13918408
You have to start somewhere!

Good luck and always use end if!

FtB
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question