Using a function instead of a variable

S

seamlyne

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
 
B

Bob Barrows [MVP]

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.
 
A

AnthonyWJones

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
 
S

seamlyne

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top