473,394 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Correct / Best way of using if..then

Jon
Hi, I can use either of the following ways of getting the same if..then
answer, which is better? Or is it personal choice. I used to always use the
second, but then had to remember to deal with double quotes etc.. The first
seems much easier..

<% ThisDay = "Monday" ' just testing !!%>
<%
If ThisDay = "Monday" Then
%>
<p>It's Monday</p>
<%
End If
%>
<!-- ------------------------------- -->
<%
If ThisDay = "Monday" Then
response.write "<p>It's Monday</p>"
End If
%>
Jul 19 '05 #1
5 1605
There used to be a performance cost in jumping in and out of blocks of ASP
code in IIS 4 on NT, but if you're running 2000 or 2003, it's all personal
preference. I use both methods. There are some pages (or parts of pages)
that have very little html, and I'll usually response.write the html out,
and then there are pages (or parts of pages) that have very little ASP, and
I will exit ASP with %> and write my html normally.

Ray at work

"Jon" <jon@SPAM_OFFtheexperts.co.uk> wrote in message
news:bs**********@sparta.btinternet.com...
Hi, I can use either of the following ways of getting the same if..then
answer, which is better? Or is it personal choice. I used to always use the second, but then had to remember to deal with double quotes etc.. The first seems much easier..

<% ThisDay = "Monday" ' just testing !!%>
<%
If ThisDay = "Monday" Then
%>
<p>It's Monday</p>
<%
End If
%>
<!-- ------------------------------- -->
<%
If ThisDay = "Monday" Then
response.write "<p>It's Monday</p>"
End If
%>

Jul 19 '05 #2
<%
Select Case ThisDay
Case Monday
Response.Write "It's Monday"
Case Tuesday
Response.Write "It's Tuesday"
Case Wednesday
Response.Write "It's Wednesday"
Case Thursday
Response.Write "It's Thursday"
Case Friday
Response.Write "It's Friday"
Case Else
Response.Write "It's something other than Mon - Fri"
End Select
%>
--
Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

Disclaimer:
I know I'm probably wrong, I just like taking part ;o)
Jon <jon@SPAM_OFFtheexperts.co.uk> wrote in message
news:bs**********@sparta.btinternet.com...
Hi, I can use either of the following ways of getting the same if..then
answer, which is better? Or is it personal choice. I used to always use the second, but then had to remember to deal with double quotes etc.. The first seems much easier..

<% ThisDay = "Monday" ' just testing !!%>
<%
If ThisDay = "Monday" Then
%>
<p>It's Monday</p>
<%
End If
%>
<!-- ------------------------------- -->
<%
If ThisDay = "Monday" Then
response.write "<p>It's Monday</p>"
End If
%>

Jul 19 '05 #3
Jon
Steve, thanks.
Ray, exactly what I was hoping for - so we're saying either is fune, just
whichever fits best at the time, great!
Jon
There used to be a performance cost in jumping in and out of blocks of ASP
code in IIS 4 on NT, but if you're running 2000 or 2003, it's all personal
preference. I use both methods. There are some pages (or parts of pages)
that have very little html, and I'll usually response.write the html out,
and then there are pages (or parts of pages) that have very little ASP, and I will exit ASP with %> and write my html normally.

Ray at work
Hi, I can use either of the following ways of getting the same if..then
answer, which is better? Or is it personal choice. I used to always use

the
second, but then had to remember to deal with double quotes etc.. The

first
seems much easier..

<% ThisDay = "Monday" ' just testing !!%>
<%
If ThisDay = "Monday" Then
%>
<p>It's Monday</p>
<%
End If
%>
<!-- ------------------------------- -->
<%
If ThisDay = "Monday" Then
response.write "<p>It's Monday</p>"
End If
%>

Jul 19 '05 #4
On Mon, 29 Dec 2003 18:14:42 -0500, "Ray at <%=sLocation%>"
<myfirstname at lane34 dot com> wrote:
There used to be a performance cost in jumping in and out of blocks of ASP
code in IIS 4 on NT, but if you're running 2000 or 2003, it's all personal
preference. I use both methods. There are some pages (or parts of pages)
that have very little html, and I'll usually response.write the html out,
and then there are pages (or parts of pages) that have very little ASP, and
I will exit ASP with %> and write my html normally.
I'm with Ray on this, though I have a tendency to separate the ASP
from the HTML. As an example with yours (which I wouldn't ever do but
it's an okay sample...):

<%
ThisDay = "Monday"
DayOutput = ""
If ThisDay = "Monday" Then
DayOutput = "It's Monday"
End If
%>
....HTML Page Stuff...
<p><% = DayOutput %></p>
....More HTML Page Stuff...

Again, it really depends on the situation, how quick the code is being
hacked together and so on. Separating the ASP and logic from the
presentation part just makes it easier for me to deal with next year
when I have to remember what I did and the comment "This section makes
the other stuff do what it needs to" just doesn't help me any more.
:)

Jeff

"Jon" <jon@SPAM_OFFtheexperts.co.uk> wrote in message
news:bs**********@sparta.btinternet.com...
Hi, I can use either of the following ways of getting the same if..then
answer, which is better? Or is it personal choice. I used to always use

the
second, but then had to remember to deal with double quotes etc.. The

first
seems much easier..

<% ThisDay = "Monday" ' just testing !!%>
<%
If ThisDay = "Monday" Then
%>
<p>It's Monday</p>
<%
End If
%>
<!-- ------------------------------- -->
<%
If ThisDay = "Monday" Then
response.write "<p>It's Monday</p>"
End If
%>


Jul 19 '05 #5
Jon
>
There used to be a performance cost in jumping in and out of blocks of ASPcode in IIS 4 on NT, but if you're running 2000 or 2003, it's all personalpreference. I use both methods. There are some pages (or parts of pages)that have very little html, and I'll usually response.write the html out,
and then there are pages (or parts of pages) that have very little ASP, andI will exit ASP with %> and write my html normally.


I'm with Ray on this, though I have a tendency to separate the ASP
from the HTML. As an example with yours (which I wouldn't ever do but
it's an okay sample...):

<%
ThisDay = "Monday"
DayOutput = ""
If ThisDay = "Monday" Then
DayOutput = "It's Monday"
End If
%>
...HTML Page Stuff...
<p><% = DayOutput %></p>
...More HTML Page Stuff...

Again, it really depends on the situation, how quick the code is being
hacked together and so on. Separating the ASP and logic from the
presentation part just makes it easier for me to deal with next year
when I have to remember what I did and the comment "This section makes
the other stuff do what it needs to" just doesn't help me any more.
:)

Jeff


<snip>

I'm just about to move over a bit from the HTML design bit and more towards
the ASP. so for me to use my 2nd version helps, I really don't interfere
with the HTML. Don't worry about the example, it was just that!

I just find that I'm forever forgetting my double quotes etc. or whatever.
in my reponse.write - the 2nd way I've got a complete HTML page, then I can
code in my ASP!

Thanks for your thoughts, and point taken about you're variation on the
example.

Jon
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Craig Ringer | last post by:
Hi folks I'm a bit of a newbie here, though I've tried to appropriately research this issue before posting. I've found a lot of questions, a few answers that don't really answer quite what I'm...
15
by: Geir Baardsen | last post by:
Hi! What is the best (correct?) way to do: Me.txtCustID.SetFocus in the OnLoad or in the OnOpen or... of the form?
102
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
3
by: Dave | last post by:
I have a piece of hardware connected via serial port. I need to send a variety of commands to the box and route the responses back from the receive thread to the correct method call. So e.g. I...
5
by: Ben Fidge | last post by:
When using Server.Transfer, the calling page name is still displayed in the browser address bar, as opposed to the called page. This is really confusing my customers! Is there a way round it? ...
50
by: Shadow Lynx | last post by:
Consider this simple HTML: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 STRICT//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head>...
9
by: klausklausenator | last post by:
Hi all, I have a php-generated webpage with images. My problem is: the Internet Explorer cannot calculate the correct image size. Because of this the images are not cached. So everytime a user...
6
by: stephen.cunliffe | last post by:
Hi, I'm looking for opinion/facts/arguments on the correct nesting of UL, OL, & LI elements. For example, this is what I want (unordered list): * Item 1 * Item 2 * Item 3
3
by: chromis | last post by:
Hi, I've been trying to create a class which will format text copy and pasted from a word document into an XML / XHTML compliant string complete with paragraphs to then be inserted into a database...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.