Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-20-2002, 03:16 PM   PM User | #1
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
VBScript -> JScript

Hey,

I'm having problems with a file that I've converted myself from VBscript to Jscript - using my rather simple algorithm "Chuck brackets round it". If someone could have a look at the two versions below and post any errors, I'd be very grateful.

VBscript version:
Code:
Option Explicit

	Dim form, page, font
	Dim oPDF
	Dim InFileMapped
	Dim lWidth, lHeight
	Dim col1, col2
	Dim buf

	col1= 70
	col2= 335

	Set oPDF = Server.CreateObject("PDFlib_com.PDF")

	' Open new PDF file
	oPDF.open_file ""

	oPDF.set_info "Creator", "personalize.vbs.asp"
	oPDF.set_info "Author", "Thomas Merz"
	oPDF.set_info "Title", "PDFlib personalization demo (Active X/VBS)"

	InFileMapped = Server.MapPath("PDFlib-purchase-order.pdf")

	form = oPDF.open_pdi(InFileMapped, "", 0)
	if (form = -1) then
		Response.write "Couldn't open input file!"
		Response.end
	end if

	page = oPDF.open_pdi_page(form, 1, "")
	if (page = -1) then
		    Response.write "Couldn't open page 1 in input file!"
		    Response.end
	end if

	font = oPDF.findfont("Helvetica-Bold", "winansi", 0)

	' get the dimensions of the imported form
	lWidth = oPDF.get_pdi_value("width", form, page, 0)
	lHeight = oPDF.get_pdi_value("height", form, page, 0)

	' start a new page
	oPDF.begin_page lWidth, lHeight

	oPDF.place_pdi_page page, 0, 0, 1, 1
	oPDF.close_pdi_page page

	oPDF.setfont font, 18
	oPDF.set_value "leading", 24
	oPDF.set_text_pos col1, 486

	oPDF.show "Doublecheck, Inc."
	oPDF.continue_text "Petra Porst"
	oPDF.continue_text "500, Market St."

	oPDF.set_text_pos col2, 104
	oPDF.continue_text DATE

	oPDF.end_page
	oPDF.close
	oPDF.close_pdi form

	buf = oPDF.get_buffer()

	Response.Expires = 0
	Response.Buffer = true
	Response.ContentType = "application/pdf"
	Response.Addheader "Content-Disposition", "inline; filename=" & "personalize.vbs.asp.pdf"
	Response.Addheader "Content-Length", LenB(buf)
	Response.BinaryWrite(buf)
	Response.End()

	Set oPDF = Nothing



JSCRIPT version:
Code:
var form;
var page;
var font;
var oPDF;
var InFileMapped;
var lWidth;
var lHeight;
var col1;
var col2;
var buf;

col1=70;
col2=335;

oPDF = Server.CreateObject("PDFlib_com.PDF");
oPDF.open_file("");
oPDF.set_info("Creator", "personalize.vbs.asp");
oPDF.set_info("Author", "Thomas Merz");
oPDF.set_info("Title", "PDFlib personalization demo (Active X/VBS)");

InFileMapped = Server.MapPath("PDFlib-purchase-order.pdf");

form = oPDF.open_pdi(InFileMapped, "", 0);
if(form = -1){
		Response.write("Couldn't open input file!");
		Response.end();
}

page = oPDF.open_pdi_page(form, 1, "");
if(page = -1){
    Response.write("Couldn't open page 1 in input file!");
    Response.end();
}


font = oPDF.findfont("Helvetica-Bold", "winansi", 0);


lWidth = oPDF.get_pdi_value("width", form, page, 0);
lHeight = oPDF.get_pdi_value("height", form, page, 0);


oPDF.begin_page(lWidth, lHeight);

oPDF.place_pdi_page(page, 0, 0, 1, 1);
oPDF.close_pdi_page(page);

oPDF.setfont(font, 18);
oPDF.set_value("leading", 24);
oPDF.set_text_pos(col1, 486);

oPDF.show("Doublecheck, Inc.");
oPDF.continue_text("Petra Porst");
oPDF.continue_text("500, Market St.")


oPDF.set_text_pos(col2, 104);
oPDF.continue_text(now())

oPDF.end_page;
oPDF.close;
oPDF.close_pdi(form);

buf = oPDF.get_buffer()

Response.Expires = 0
Response.Buffer = true
Response.ContentType = "application/pdf"
Response.Addheader("Content-Disposition", "inline; filename=" & "personalize.vbs.asp.pdf");
Response.Addheader("Content-Length", LenB(buf));
Response.BinaryWrite(buf);
Response.End();

delete oPDF;

Thanks
Spudhead is offline   Reply With Quote
Old 06-20-2002, 03:43 PM   PM User | #2
landon11
Regular Coder

 
Join Date: Jun 2002
Location: USA
Posts: 113
Thanks: 0
Thanked 0 Times in 0 Posts
landon11 is an unknown quantity at this point
Why do you want to change it to JScript?
__________________
USA
landon11 is offline   Reply With Quote
Old 06-20-2002, 04:01 PM   PM User | #3
RadarBob
Regular Coder

 
Join Date: Jun 2002
Location: Round Rock, Texas
Posts: 443
Thanks: 0
Thanked 0 Times in 0 Posts
RadarBob is an unknown quantity at this point
Quote:
Why do you want to change it to JScript?
IMHO, dealing with fewer computer languages is always better. Especially if YOU are the maintenance programmer. I want to eventually address this same issue for the web site I have recently been assigned to maintain. With multiple languages, one is less likely to become a true master of any one. Why do you think some of these books on Web development technologies have 2, 4, even 8 (!) authors?

So far I've seen no compelling reason to use both VBScipt and JavaScript; but from a code management point of view, plenty of reason not to.

All the books one buys on ASP "teach" utilizing VBScript on the server side. Except for bending to the will of Microsoft, why do this? If I have to pay for all the training, books, tools, etc. necessary for using both languages in my coding shop you better have excellent reasons. So what are they; anyone?

Last edited by RadarBob; 06-20-2002 at 04:04 PM..
RadarBob is offline   Reply With Quote
Old 06-20-2002, 04:28 PM   PM User | #4
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
Specifically, because this bit of VBscript I'm trying to convert has got to sit in amongst a HUGE page of Jscript. If someone tells me how to use two different server-side languages safely on the same page, passing variables between them and the rest of it, then I guess I don't have a problem - can anyone help me there? More generally, because I started off in Javascript, and know very little VB, so Jscript is a more comfortable language for me to write in.
Spudhead is offline   Reply With Quote
Old 06-21-2002, 12:30 AM   PM User | #5
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
<script language="VBScript" runat="server">

...

ASP has no problem running two languages on the same page... I haven't tried it SPECIFICALLY like above, but I use javascripts on VBScript pages, just because sometimes they are easier/shorter, when usually VBScript is easier.

I personally don't care if there is more than one scripting language on a page - as long as it works!!!
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Old 06-21-2002, 03:07 PM   PM User | #6
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
Cheers Whammy - me neither

Unfortunately:

Code:
<html>
<head></head>
<body>
<script language="VBSCRIPT" runat="server">
Dim myvar
myvar="hello"
</script>
<script language="JSCRIPT" runat="server">
Response.Write(myvar);
</script>
</body>
</html>
results in:

Microsoft JScript runtime error '800a1391'
'myvar' is undefined
Spudhead is offline   Reply With Quote
Old 06-22-2002, 12:59 AM   PM User | #7
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
Uh... like I said, I'm no server-side javascript master, so I'm not quite sure what you're doing wrong; but here's an example that DOES work:

<% @Language="VBScript" %>
<script language="javascript" runat="server">
var myvar = "Hello World!"
</script>

<%
Response.Write(myvar)
%>

Tried and tested...

__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)

Last edited by whammy; 06-22-2002 at 01:09 AM..
whammy is offline   Reply With Quote
Old 06-24-2002, 06:58 AM   PM User | #8
Roelf
Senior Coder

 
Join Date: Jun 2002
Location: Zwolle, The Netherlands
Posts: 1,110
Thanks: 2
Thanked 28 Times in 28 Posts
Roelf is on a distinguished road
I found 2 small errors in your code, don't know if correcting them will fix it but here they are>

the comparision:
if(form = -1)
should be:
if(form == -1)

and the same goes a few lines later for the page variable

maybe this helps

Roelf
Roelf is offline   Reply With Quote
Old 06-24-2002, 02:07 PM   PM User | #9
RadarBob
Regular Coder

 
Join Date: Jun 2002
Location: Round Rock, Texas
Posts: 443
Thanks: 0
Thanked 0 Times in 0 Posts
RadarBob is an unknown quantity at this point
SH;
It's interesting that you define the variable in one language, and try to use it in another. I don't see how the Javascript compiler(?) can know about the results/object code/whatever of the VBScript compiler(?).

Maybe use a function to pass the value as a parameter?

Now if the above is BS, maybe this?...


<script language="VBSCRIPT" runat="server">
Dim myvar
myvar="hello"
</script>
<script language="JSCRIPT" runat="server">
Response.Write(<%myvar%>);
</script>
RadarBob is offline   Reply With Quote
Old 06-24-2002, 11:45 PM   PM User | #10
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
If you don't believe me about the code I posted above, it's at:

http://www.solidscripts.com/languages.asp

...of course, all you'll see if you view the source is "Hello World!", though...
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Old 06-25-2002, 01:14 PM   PM User | #11
RadarBob
Regular Coder

 
Join Date: Jun 2002
Location: Round Rock, Texas
Posts: 443
Thanks: 0
Thanked 0 Times in 0 Posts
RadarBob is an unknown quantity at this point
whammy;

Oh, I think I see. RESPONSE is an ASP object, not a Javascript object. By completely surrounding the statement w/ the ASP tag, ASP will evaluate it, not Javascript.

I guess ASP objects simply have access to variables declared in VBScript and Javascript.
RadarBob is offline   Reply With Quote
Old 06-26-2002, 01:49 AM   PM User | #12
whammy
Senior Coder

 
Join Date: Jun 2002
Location: 41° 8' 52" N -95° 53' 31" W
Posts: 3,660
Thanks: 0
Thanked 0 Times in 0 Posts
whammy is an unknown quantity at this point
That's a good assumption (it seems to ring true to me, at any rate);

I didn't see any ASP tags surrounding the javascript or have a chance to test it though, since I usually only use javascript in functions on VBScript pages.
__________________
Former ASP Forum Moderator - I'm back!

If you can teach yourself how to learn, you can learn anything. ;)
whammy is offline   Reply With Quote
Old 11-21-2007, 12:49 PM   PM User | #13
toughy
New to the CF scene

 
Join Date: Nov 2007
Location: Bucharest, Romania
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
toughy is an unknown quantity at this point
Quote:
Originally Posted by RadarBob View Post
IMHO, dealing with fewer computer languages is always better. Especially if YOU are the maintenance programmer. I want to eventually address this same issue for the web site I have recently been assigned to maintain. With multiple languages, one is less likely to become a true master of any one. Why do you think some of these books on Web development technologies have 2, 4, even 8 (!) authors?

So far I've seen no compelling reason to use both VBScipt and JavaScript; but from a code management point of view, plenty of reason not to.

All the books one buys on ASP "teach" utilizing VBScript on the server side. Except for bending to the will of Microsoft, why do this? If I have to pay for all the training, books, tools, etc. necessary for using both languages in my coding shop you better have excellent reasons. So what are they; anyone?
One good reason I use mostly JScript in my server pages is that as a web developer I already know JavaScript. Client-side JavaScript is supported in browsers on many, many platforms so learning it is a good investment, while Basic and VBScript are mostly supported by Microsoft. How many web pages have you seen or even wrote that use client-side VB scripts ? And all books teach VBScript just to go with the flow given by Microsoft. But even the Script Developer guide from MSDN teaches both anyway ...

And then there is also the issue of each language having its advantages and disadvantages. JavaScript is more formal and technical for me, and as a C++ programmer I want that from the language I choose to script with.

Now I can work with both of them anyway. Even though you are right that I do not master any one of them, I think I should learn them both, and then if I want I can specialise into one.
toughy is offline   Reply With Quote
Old 11-21-2007, 06:51 PM   PM User | #14
Spudhead
Senior Coder

 
Spudhead's Avatar
 
Join Date: Jun 2002
Location: London, UK
Posts: 1,856
Thanks: 8
Thanked 110 Times in 109 Posts
Spudhead is on a distinguished road
Is this a record for the deepest thread-digging ever??
Spudhead is offline   Reply With Quote
Old 11-21-2007, 10:09 PM   PM User | #15
toughy
New to the CF scene

 
Join Date: Nov 2007
Location: Bucharest, Romania
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
toughy is an unknown quantity at this point
Quote:
Originally Posted by Spudhead View Post
Is this a record for the deepest thread-digging ever??
I do not know, it might well be, as I did not look at the date when I replied.

I found the thread yesterday.
I was searching for a way to create data of the COM (ActiveX) data type VT_ARRAY | VT_UI1 with JScript, as I want to output an Excel workbook from one of my web scripts, with Response.BinaryWrite, and BinaryWrite needs an object of that data type. Unfortunately JScript knows little about data types...

I did not even look at the year.
Anyway both VBScript and JScript are in use today, as ASP is, so the question is still up-to-date.

Timothy Madden,
Romania
toughy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:37 PM.


Advertisement
Log in to turn off these ads.