...

View Full Version : VBScript -> JScript



Spudhead
06-20-2002, 03:16 PM
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:


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:


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 :)

landon11
06-20-2002, 03:43 PM
Why do you want to change it to JScript?

RadarBob
06-20-2002, 04:01 PM
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?

Spudhead
06-20-2002, 04:28 PM
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.

whammy
06-21-2002, 12:30 AM
<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!!!

Spudhead
06-21-2002, 03:07 PM
Cheers Whammy - me neither :)

Unfortunately:



<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

whammy
06-22-2002, 12:59 AM
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...

:confused:

Roelf
06-24-2002, 06:58 AM
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

RadarBob
06-24-2002, 02:07 PM
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>

whammy
06-24-2002, 11:45 PM
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... ;)

RadarBob
06-25-2002, 01:14 PM
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.

whammy
06-26-2002, 01:49 AM
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.

toughy
11-21-2007, 12:49 PM
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.

Spudhead
11-21-2007, 06:51 PM
Is this a record for the deepest thread-digging ever?? :D

toughy
11-21-2007, 10:09 PM
Is this a record for the deepest thread-digging ever?? :D

I do not know, it might well be, as I did not look at the date when I replied. :thumbsup:

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum