469,271 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Using a function instead of a variable

Windows Server 2003, IIS 6, ASP Classic

I need to do something like this:

dim pageNum
pageNum = request("page")
if pageNum = "" then pageNum = 1

....and I need to do it several times. Another approach would be to do
this:

function fnPageNum
fnPageNum = request("page")
if fnPageNum = "" then fnPageNum = 1
end function

dim pageNum
pageNum = fnPageNum

In one method more efficient than the other, or do IIS not care either
way?

Bill in Kansas City

Jan 17 '06 #1
3 1157
se******@hotmail.com wrote:
Windows Server 2003, IIS 6, ASP Classic

I need to do something like this:

dim pageNum
pageNum = request("page")
if pageNum = "" then pageNum = 1

...and I need to do it several times. Another approach would be to do
this:

function fnPageNum
fnPageNum = request("page")
if fnPageNum = "" then fnPageNum = 1
end function

dim pageNum
pageNum = fnPageNum

In one method more efficient than the other, or do IIS not care either
way?

IIS does not care. For pure maintainability, I would use the function. The
criterion is: never write the same sequence of code more than once. If it
needs to be done more thaan once, encapsulate it in a sub or a function.

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jan 17 '06 #2
Use a generic function like this:-

dim pageNum

pageNum = GetRequestValue("page", 1)

Function GetRequestValue(Name, Default)
GetRequestValue = Request(Name)
If GetRequestValue = Empty Then
GetRequestValue = Default
End If
End Function
"se******@hotmail.com" wrote:
Windows Server 2003, IIS 6, ASP Classic

I need to do something like this:

dim pageNum
pageNum = request("page")
if pageNum = "" then pageNum = 1

....and I need to do it several times. Another approach would be to do
this:

function fnPageNum
fnPageNum = request("page")
if fnPageNum = "" then fnPageNum = 1
end function

dim pageNum
pageNum = fnPageNum

In one method more efficient than the other, or do IIS not care either
way?

Bill in Kansas City

Jan 17 '06 #3
That's sort of where I was to begin with, but I figured I'd ask.
Ultimately, while I was waiting for the reply, that's what I did
anyway. I have a rather large project, and it made sense.

Thanks for taking the time!

- Bill

Jan 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

28 posts views Thread by Daniel | last post: by
5 posts views Thread by Dmitriy Lapshin [C# / .NET MVP] | last post: by
4 posts views Thread by Immortal_Nephi | last post: by
reply views Thread by Luis Zarrabeitia | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.