Can you convert the following JavaScript to VBScript ?
<SCRIPT LANGUAGE="JavaScript">
// alterError - fixes a rounding bug in Netscape 2
function alterError(value) {
if (value<=0.99) {
newPounds = '0';
} else {
newPounds = parseInt(value);
}
newPence = parseInt((value+.0008 - newPounds)* 100);
if (eval(newPence) <= 9) newPence='0'+newPence;
newString = newPounds + '.' + newPence;
return (newString);
}
// buyItem - adds an item to the shopping basket
function buyItem(newItem, newPrice, newQuantity) {
if (newQuantity <= 0) {
rc = alert('The quantity entered is incorrect');
return false;
}
if (confirm('Add '+newQuantity+' x '+newItem+' to basket')) {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
document.cookie="TheBasket="+document.cookie.substring(countbegin,
countend)+"["+newItem+","+newPrice+"#"+newQuantity+"]";
}
return true;
}
// resetShoppingBasket - resets to shopping basket to empty
function resetShoppingBasket() {
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket=.";
}
</SCRIPT>
<BODY>
<SCRIPT LANGUAGE="JavaScript">
// alterError - fixes a rounding bug in Netscape 2
function alterError(value) {
if (value<=0.99) {
newPounds = '0';
} else {
newPounds = parseInt(value);
}
newPence = parseInt((value+.0008 - newPounds)* 100);
if (eval(newPence) <= 9) newPence='0'+newPence;
newString = newPounds + '.' + newPence;
return (newString);
}
// showItems () - creates a table of items in the basket and
// creates the start of a form which sets information for
// basket items.
function showItems() {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
document.writeln('<FORM action="bfinish.htm" target="_top">');
document.writeln('<TABLE BORDER COLS=4>');
document.writeln('<TR><TD><b>Item</b></TD><TD><b>Quantity</b></TD><TD><b>Cost
Each</b></TD><td><b>Total Cost</b></TR>');
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
totprice = totprice + itemtotal;
itemlist=itemlist+1;
document.writeln('<tr><td>'+theitem+'</td><td
align=right>'+thequantity+'</td><td align=right>'+theprice+'</td><td
align=right>'+alterError(itemtotal)+'</td></tr>');
document.writeln('<INPUT TYPE="hidden" NAME="item'+itemlist+'"
VALUE="'+theitem+'" SIZE="40">');
document.writeln('<INPUT TYPE="hidden" NAME="quantity'+itemlist+'"
VALUE="'+thequantity+'" SIZE="40">');
document.writeln('<INPUT TYPE="hidden" NAME="price
each'+itemlist+'" VALUE="'+theprice+'" SIZE="40">');
document.writeln('<INPUT TYPE="hidden" NAME="total
cost'+itemlist+'" VALUE="'+alterError(itemtotal)+'" SIZE="40">');
} else if (fulllist.substring(i,i+1) == ',') {
theitem = fulllist.substring(itemstart, i);
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == '#') {
theprice = fulllist.substring(itemstart, i);
itemstart = i+1;
}
}
document.writeln('<tr><td colspan=3><b>Total</b></td><td
align=right>'+alterError(totprice)+'</td></tr>');
document.writeln('<INPUT TYPE="hidden" NAME="Goods Total"
VALUE="'+alterError(totprice)+'" SIZE="40">');
document.writeln('</TABLE>');
}
</SCRIPT>
</SCRIPT>
<center>
<h2>Buy Goods...</h2>
<!-- call showItems to show items in basket -->
<SCRIPT LANGUAGE="JavaScript">
showItems();
</SCRIPT> |