Guestbook creation with ASP - using ActiveX & JScript (Posted by lloydhass)

They have: 5,633 posts

Joined: Jan 1970

I have been working on an ASP guestbbok using Jscript. The only tutorials I have come across explain how to do this with VBScript. Does anybody know of a good ASP/JScript resource on the net?

I am using a text file to store information. I want to read each line one by one - store the line as a variable - then display the variable. I do know how to do this with VBScript but I want to learn the alternative. Here is the code I have used so far.

<%
var guestFile = 'guestbook.txt';
var filesys = new ActiveXObject("Scripting.FileSystemObject");
var guestbookFile = filesys.OpenTextFile(guestFile,1);

var currentLine;

while(?) {
// read line
// set the 'currentLine' variable
%>
<%=currentLine%>
<%
// loop to next line?
}

guestbookFile.Close();

%>

Any help in this area would be greatly appreciated.

----------
[email protected]
http://go.to/hass

They have: 112 posts

Joined: Apr 1999

lloyd,
Isn't that Jscript???
Later

Joe Thong

----------
http://phpdb.linuxbox.com/
A free database wrapper project!

They have: 112 posts

Joined: Apr 1999

PJ,
What makes you think that Jscript is ineffective? Can you please elaborate?
Llyod,
I have once written a file reading script. Here's the code, HOpe it helps.
var file = "users.db";
var fs = Server.CreateObject("Scripting.FileSystemObject");
var a = fs.OpenTextFile(Server.MapPath(file));
while (!(a.AtEndofStream)) {
var arrs = new Array();
var str = a.ReadLine();
splitMe(str, "¦", arrs);
username = arrs[0];
password = arrs[1];
if (username == Request.Form("username") && password == Request.Form("password")) {
Session("news_author") = username;
Response.Redirect("admin.asp");
}
else {
Response.Redirect("login_failed.asp");
}
}
a.close();

Later

Joe Thong

----------
http://phpdb.linuxbox.com/
A free database wrapper project!

They have: 76 posts

Joined: Apr 1999

Elera,

I'm not saying that as a scripting language in general that JScript is ineffective, since they're all fairly similar. It really depends on what you're trying to achieve. I think for this particular example VBScript handles the job much easier. I guess that's just how I classify effective, if I can achieve the same result with less code, that equals more effective to me.

I don't have anything against JScript (or JavaScript) since I code in them all the time. Smiling

Later,
PJ

They have: 5,633 posts

Joined: Jan 1970

=elara=

Yeah it is JScript but I don'y know the code for reading the current line of a text file or advancing to the next line. And also I don't know what code to put in the while loop.

----------
[email protected]
http://go.to/hass

They have: 76 posts

Joined: Apr 1999

lloydhass,

I know you're trying to figure this out in JScript but why? This is so easy with VBScript, just set up a Do While not guestbookfile.EOF loop and you're done.

To get the same thing done with JScript you're going to have to setup some sort of variable for guestbook.EOF and then setup a loop like:

for(x=0;x<guestbook.EOF;x++)
{
Do work here
}

It's possible but I'm not sure why you would want to use a way that's harder and more ineffective than VBScript.

Later,
PJ

They have: 5,633 posts

Joined: Jan 1970

=PJ=
I have quite a bit of experience with JavaScript so I am going to stick with the language I am already familiar with. VBScript looks very easy to code but I just don'w want to fill my head with another language at the moment. It's hard enough for me to remember JavaScript as it is.

=elara=
Thanks for posting that script. I was after the AtEndofStream and the ReadLine(); code. I am still looking for a JScript reference site or ActiveX. I went to the best IT bookstore in the city and they didn't have any ActiveX books in the store. The only ASP books they had were all written in VBScript.

Just curious, did you fellow ASP programmers learn JavaScript before VBScript?

----------
[email protected]
http://go.to/hass - http://connect.to/wpd

They have: 112 posts

Joined: Apr 1999

PJ,
Is good to hear that Jscript is a good language. I have nothing against vbscript, but is just that code without a semi-colon at the behind of each line is very weird and troublesome for me.
Llyod,
I learnt Javascript before than vbscript. I learnt vbscript when I want to learn asp because none of the documentation or examples are written in jscript. * sigh * It really took me a long time to pick up asp with jscript.
There's a good reference for Jscript/ASP functions. Visit www.microsoft.com/scripting and look for the jscript documentation. The reference is a need for every jscript/asp programmer, but beware there are some broken code examples. I have once had a jscript/asp problem with the dictionary object because I copied an unusable code from the reference... It took me few days to realise that its their fault instead of mine.
Hope this helps.
Later.

Joe Thong

----------
http://phpdb.linuxbox.com/
A free database wrapper project!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.