Google Answers Logo
View Question
 
Q: "Java Script to VB Script" ( No Answer,   0 Comments )
Question  
Subject: "Java Script to VB Script"
Category: Computers > Programming
Asked by: sankara5-ga
List Price: $20.00
Posted: 18 Sep 2005 01:20 PDT
Expires: 28 Sep 2005 19:19 PDT
Question ID: 569315
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>
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy