The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Funky Functions in ASP

There is already a thread like this, but it was filled with alot of general chit-chat and stuff, so I decided to start a new one. Please, keep chat to a minimal, just post your functions os other peopel can easily use them without siffing thru chat.

display code in browser

here's a simple one that I use a lot...

Code:

function displayCode(page_to_display)
set fsObj = CreateObject("Scripting.FileSystemObject")
set fileObj = fsObj.OpenTextFile(server.mappath(page_to_display),1,false)
do while not fileObj.AtEndOfStream
''' read the current line and write it to the browser
response.write server.htmlencode(fileObj.readline) & "<br>"
loop
fileObj.Close
set fileObj = NOTHING
set fsObj = NOTHING
end function

I wrote the following function years ago as a quick & dirty solution to the problem of checking if session & form variables (and cookies) have been initialised. This usually requires doing multiple checks for IsNull, IsEmpty, etc. I wrapped these up (and more in this function) in this function to save time, and make my coding more efficient.

It returns true if the variable is an array with no dimensions, and object (which by definition must mean that the variable is initialised, and thus not empty), or a plain old variant which is either Null, Empty, or equal to "". In all other cases it returns false. I've found it to cover all the bases for me! :-)

MS SQL Stored Procedures

I have an ASP page for creating ASP pages to call SQL Server stored proceudres for updates/inserts. It generates all of the ASP/HTML you need. It's *way* too long to post here, but if anyone would find it useful, let me know.

Regarding M@rco's post with the InteliDev link. InteliDev.com is currently unavailable because of a fluke combination of events that happened about 3 weeks ago. My apologies if you were looking for the HTMLParser class at InteliDev. I am trying to get the site back online, but I can't seem to find the time. I will post a function for getting XML/ish attribute values without using RegExp in a little bit.

OK, I put all my functions (that are posted here) at the Bad Syntax Code Library, and added a couple more. I will be updating the Code Library every day until I get all my functions and schemas posted. Right now I will be concentrating on posting ASP, PHP, and SQL, but will expand to add Python, Java, VB, JS, etc as time allows and the become available. When I have some time, I will make it all DB driven, search, etc - might even add a comment system, etc and see if it can become the #1 code library on the net.

If anyone has anything to contribute, just drop me an email and we can discuss it. WARNING: any contributed snippets will be subject to formatting and/or syntax changes. I will NOT post ugly code.

Issue with RS Paging posting....

Hi DHTML god,

With regards to your previous posting on RS paging. Cool functions except I struggled when reaching page numbers => 110....!!
Do you have any idea why this happens? is it something to do with assuming pages will be less than 3 numbers and therefore the function assumes a 1?

So you have a main page which you would like quicker. If your hitting the database everytime someone visits your page and the database has the same data why do it?

Use caching instead. The following sub procedure when you call it will fetch the page you wish to cache and write this to a static HTML file.
[VBS]
Sub CachePage (PageToCache, HTMLPageToWrite)
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

Dim xml
Set xml = Server.CreateObject("Microsoft.XMLHTTP")

'Opens the connection to the page you wish to cache
xml.Open "GET", PageToCache, False

'Actually Sends the request and returns the data from the page you wish to cache
xml.Send

'Clean up our objects
Set objTextStream = Nothing
Set objFSO = Nothing
Set xml = Nothing
End Sub
[/VBS]
For example I use this for my index page when someone updates the news I call this sub procedure which will get the latest page from index_0.asp and write it to a HTML file called index.htm therefore my index page is much quicker as I am not hitting the database every time.

To call the procedure:
[VBS]
CachePage "http://www.yourdomain.co.uk/index_0.asp", "D:\yourhostdirectory\index.htm"
[/VBS]
You need to have microsoft's free XMLHTTP component installed which most hosts do, to use this caching technique.

To use the latest version of XMLHTTP use this line instead:
[VBS]
Set xml = Server.CreateObject("MSXML2.ServerXMLHTTP.3.0")
[/VBS]

Thanks this is a very useful of removing to need to always call the DB. Cheers...

However.. my point was the ability to acurately group pages drawn from a database into page numbers. Whilst this is fine for pages up to 110, on recordsets larger than this fails when a user clicks upon it based upon DHTML two functions previously posted. I was enquiring how this could be fixed to have the 'previous' and 'next' buttons working efficiently...Does this make sense?

I have seen another way to do this ny just retrieving the records for that page. But I cannot use Stored Procedures because I require to dynamically change the order field. I understand this is not possible because you cannot assign a local var to this.