Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Snitz Forums 2000 DEV-Group
 DEV Discussions (General)
 MIssing end ifs
 New Topic  Topic Locked
 Printer Friendly
Next Page
Author Previous Topic Topic Next Topic
Page: of 2

snaayk
Senior Member

USA
1061 Posts

Posted - 01 September 2002 :  17:20:25  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
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  Show Profile  Visit burthold's Homepage
if then
elseif
end if
is valid.
Go to Top of Page

RichardKinser
Snitz Forums Admin

USA
16655 Posts

Posted - 01 September 2002 :  17:24:20  Show Profile
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
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 01 September 2002 :  17:53:46  Show Profile

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)
Go to Top of Page

alex042
Average Member

USA
631 Posts

Posted - 02 September 2002 :  00:27:01  Show Profile  Send alex042 an AOL message  Send alex042 a Yahoo! Message
quote:

if x = 1 then y = 2 : Z = 3


Do multiple cases work this way too? Say, Case 1:2?



Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 02 September 2002 :  01:06:10  Show Profile
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
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 02 September 2002 :  02:37:21  Show Profile
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
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 02 September 2002 :  02:43:54  Show Profile
quote:
Originally posted by GauravBhabu
(except for missing criteria for select case)

Oops!

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 02 September 2002 :  11:47:11  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
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?
Go to Top of Page

Nikkol
Forum Moderator

USA
6907 Posts

Posted - 02 September 2002 :  11:52:30  Show Profile
Correct snaayk

Nikkol ~ Help Us Help You | ReadMe | 3.4.03 fixes | security fixes ~
Go to Top of Page

alex042
Average Member

USA
631 Posts

Posted - 02 September 2002 :  12:18:50  Show Profile  Send alex042 an AOL message  Send alex042 a Yahoo! Message
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
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 02 September 2002 :  12:51:47  Show Profile  Visit D3mon's Homepage
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"
Go to Top of Page

GauravBhabu
Advanced Member

4288 Posts

Posted - 02 September 2002 :  15:02:38  Show Profile
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)
Go to Top of Page

snaayk
Senior Member

USA
1061 Posts

Posted - 02 September 2002 :  20:03:48  Show Profile  Visit snaayk's Homepage  Send snaayk an AOL message  Send snaayk an ICQ Message  Send snaayk a Yahoo! Message
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?
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 02 September 2002 :  20:18:03  Show Profile  Visit D3mon's Homepage
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"
Go to Top of Page

Deleted
deleted

4116 Posts

Posted - 03 September 2002 :  07:12:39  Show Profile
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!
Go to Top of Page
Page: of 2 Previous Topic Topic Next Topic  
Next Page
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000 Version 3.4.07