Author |
Topic |
snaayk
Senior Member
USA
1061 Posts |
Posted - 01 September 2002 : 17:20:25
|
In case theres a new way....
There are a few places where (I think) there are missing end ifs.
Does every If need an End. I always thought so, but since I have found a few that apparently dont, but the page has no error, I'm not sure... |
|
burthold
Junior Member
USA
426 Posts |
Posted - 01 September 2002 : 17:21:47
|
if then elseif end if is valid. |
|
|
RichardKinser
Snitz Forums Admin
USA
16655 Posts |
Posted - 01 September 2002 : 17:24:20
|
if there was a missing end if, the page would not load, and you'd get an error message.
are you referring to things like this?
if x = 1 then Response.Write x |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 01 September 2002 : 17:53:46
|
Example 1
if x = 1 then y = 2 : Z = 3
Example 2
if x = 1 then
y = 2 : z = 3
end if
Example 3
if x = 1 then
y = 2
z = 3
end if
The three examples above will process equally. You can use : to have multiple statements on the same line. However it is good practice to write each statement on a separate line. |
CSS and HTML4.01 Compilant Snitz Forum . ForumSquare . Rakesh Jain
It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.
Prayer Of Forgiveness "I forgive all living beings. May all living beings forgive me! I cherish the friendliness towards all and harbour enmity towards none." -- Aavashyaka Sutra(Translated) |
|
|
alex042
Average Member
USA
631 Posts |
Posted - 02 September 2002 : 00:27:01
|
quote:
if x = 1 then y = 2 : Z = 3
Do multiple cases work this way too? Say, Case 1:2?
|
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
Posted - 02 September 2002 : 01:06:10
|
With Case statements, multiple cases can be separated by commas. (I'm pretty sure anyway.) Like this:
Select Case
Case 1,2
do something here
Case 3
do something else
End Select
|
Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~ |
Edited by - Nikkol on 02 September 2002 01:08:29 |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 02 September 2002 : 02:37:21
|
Nikol is right (except for missing criteria for select case) and you can also do like...
Select case x
Case 0 : y = 0 : z = 0
Case 1 : y = 2 : z = 3
end select
|
Edited by - GauravBhabu on 02 September 2002 02:38:49 |
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
|
snaayk
Senior Member
USA
1061 Posts |
Posted - 02 September 2002 : 11:47:11
|
quote: Originally posted by RichardKinser
if there was a missing end if, the page would not load, and you'd get an error message.
are you referring to things like this?
if x = 1 then Response.Write x
yep. Them are the ones! So an end if is not neccessary in that case? |
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
|
alex042
Average Member
USA
631 Posts |
Posted - 02 September 2002 : 12:18:50
|
Is there a way to close a database connection without the close statement? I'm asking because there have been instances when I try to close a connection in some code and I get an error telling me it's already closed when there are no other close statements in the code. Is there something in this situation that may be similiar to not requiring an end if?
|
Edited by - alex042 on 02 September 2002 12:59:02 |
|
|
D3mon
Senior Member
United Kingdom
1685 Posts |
Posted - 02 September 2002 : 12:51:47
|
Ideally the close DB statement should check to see if there is an open connection first before closing it. I've seen an example somewhere on one of the more popular ASP sites - can't remember now though |
Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod "In war, the victorious strategist only seeks battle after the victory has been won" |
|
|
GauravBhabu
Advanced Member
4288 Posts |
Posted - 02 September 2002 : 15:02:38
|
You can always check the status of connection by using the following code:
if myConn.State = 1 then myConn.Close
|
CSS and HTML4.01 Compilant Snitz Forum . ForumSquare . Rakesh Jain
It is difficult to IMPROVE on Perfection, There is no harm in Keep Trying.
Prayer Of Forgiveness "I forgive all living beings. May all living beings forgive me! I cherish the friendliness towards all and harbour enmity towards none." -- Aavashyaka Sutra(Translated) |
|
|
snaayk
Senior Member
USA
1061 Posts |
Posted - 02 September 2002 : 20:03:48
|
Imagine all the end ifs I could have saved
How about this:
if y = abc then Response.Write "Hello"
is less or more server intensive than:
if y = abc then Response.Write "Hello" end if
I guess then unless theres an else you might as well use the first example above? |
|
|
D3mon
Senior Member
United Kingdom
1685 Posts |
Posted - 02 September 2002 : 20:18:03
|
Two things:
1) Using the end if's makes the code much easier to read and debug (if correctly indented)
2) I would imagine that the end if is 'assumed' in the first case - that is to say that the parsing engine will include it anyway. So I expect no time is saved in omitting it. |
Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod "In war, the victorious strategist only seeks battle after the victory has been won" |
|
|
Deleted
deleted
4116 Posts |
Posted - 03 September 2002 : 07:12:39
|
quote:
2) I would imagine that the end if is 'assumed' in the first case - that is to say that the parsing engine will include it anyway. So I expect no time is saved in omitting it.
Especially with IIS 5.x where the ASP pages are kept precompiled.
For me, the decision purely depends on context.
if strBlaBla="bla" then Response.Write "bla"
if strBlaBla2="bla2" then Response.Write "bla2"
if strBlaBla3="bla3" then Response.Write "bla3"
will be less readable if we use the other form:
if strBlaBla="bla" then
Response.Write "bla"
end if
if strBlaBla2="bla2" then
Response.Write "bla2"
end if
if strBlaBla3="bla3" then
Response.Write "bla3"
end if
|
Stop the WAR! |
|
|
Topic |
|