Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change VBScript to asp 1

Status
Not open for further replies.

glenmac

Technical User
Jul 3, 2002
947
CA
I've got this script I'd like to use on a web page using ASP. My problem is getting the loop to work for the input part of the script.Can anyone point me in the right direction?
Code:
dim varA
dim varB
dim varC
dim varT
dim tottax
dim Array(1000)
dim Tarray(1000)
dim TotalCarray(1000)
dim TotalQarray(1000)
Num=0

	do' user input loop

		varA = Inputbox ("input Item") 'Gets user input for items

		varB =CInt (Inputbox ("input quantity")) 'Gets user input for quantity

		varC = CInt (Inputbox ("input Cost")) 'Gets user input for Cost

		varT = CInt (Inputbox ("input current taxrate ")) ' Gets user input for taxrate

		tottax=varT * (varB * varC)/100

		Tarray(num) = tottax
		TotalCArray(num) = varC
		TotalQArray(num) = varb

		Array(num) ="You've odered "& Varb & " " & varA & "s at " & varC & "$ per  " & varA & " the tax rate is  " & varT &" %"

		num = num+1

		continue = Msgbox("Do you really want to continue",4)
	loop while continue  = 6 'loop while continue equals yes 
	x = 0
	for j = 0 to num-1'display loop


		WScript.Echo Array(i)
	 	WScript.Echo "The tax is "&Tarray(i)
		x= Tarray(i) + x
		y= TotalCArray(i) + y
		z= TotalQArray(i) + z
		i = i + 1
	
	Next
	
wscript.echo x & " is total tax"&"$"    'final display
wscript.echo (y * z) + x  & " is the total cost"&"$"
 
hi there,
you're really going to have to change that one around,
input and msgbox's of course are not available in asp so you could just use a form and then submit it and run the calculation. honestly it may be easier jsut to start over and rewrite the script from scratch using this one as a template in a sense.
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Try this:
(Note that you should name this file costcalc.asp)

Code:
<%
if request.form(&quot;submission&quot;) = &quot;Order item&quot; then
	arrOrders = session(&quot;arrOrders&quot;)
	if varType(arrOrders) > 8191 then
		redim preserve arrOrders(3,ubound(arrOrders,2)+1)
	else
		redim arrOrders(3,0)
	end if
	intUpper = ubound(arrOrders,2)
	intTax = cint(request.form(&quot;Tax&quot;))
	intQuantity = cint(request.form(&quot;Quantity&quot;))
	intPrice = cint(request.form(&quot;Price&quot;))
	strItem = request.form(&quot;Item&quot;)
	arrOrders(0,intUpper) = intTax * (intQuantity * intPrice) / 100
	arrOrders(1,intUpper) = request.form(&quot;Quantity&quot;)
	arrOrders(2,intUpper) = request.form(&quot;Price&quot;)
	arrOrders(3,intUpper) = &quot;You've ordered &quot;& intQuantity & &quot; &quot; & strItem & &quot;s at &quot; & intPrice & &quot;$ per  &quot; & strItem & &quot; the tax rate is  &quot; & intTax &&quot; %&quot;
	session(&quot;arrOrders&quot;) = arrOrders
end if
if varType(arrOrders) < 8192 then
	arrOrders = session(&quot;arrOrders&quot;)
end if
if varType(arrOrders) > 8191 then
	for t = 0 to ubound(arrOrders,2)
		response.write arrOrders(3,t) & &quot;<br>The tax is &quot; & arrOrders(0,t) & &quot;<br>&quot;
		intSumTax = intSumTax + arrOrders(0,t)
		intSumCost = intSumCost + (arrOrders(1,t)*arrOrders(2,t))
	next
	response.write intSumTax & &quot;$ is the total tax<br>&quot; & intSumCost & &quot; is the total cost...&quot;
end if
%>
<html>
<body>
<form action=costcalc.asp method=post name=theForm ID=&quot;Form1&quot;>
Item <input type=text ID=&quot;Text1&quot; NAME=&quot;Item&quot;><br>
Quantity <input type=text ID=&quot;Text2&quot; NAME=&quot;Quantity&quot;><br>
Price <input type=text ID=&quot;Text3&quot; NAME=&quot;Price&quot;><br>
Taxrate <input type=text ID=&quot;Text4&quot; NAME=&quot;Tax&quot;><br>
Submit <input name=submission value='Order item' type=submit>
</form>
</body>
</html>
This is not a bug - it's an undocumented feature...
;-)
 
... btw: it seemed to me that you summed all of you quantities and itemprices and multiplied them outside the loop, which doesn't seem right...
3*§10 + 5*§2 is not the same as 8*§12 This is not a bug - it's an undocumented feature...
;-)
 
Is it possible to run a loop with a form including text boxes to replace the input boxes box with a radio buttons to replace the message box .Changing wscipt.echo with document.write. I could replace the calculations by turning them into functions and calling them couldn't I?
My main problem is I don't know how to loop a form. Is it possible? I guess I could recall the page but then how could I fill the arrays? Hmm maybe I could use a cookie and update the cookie???? ( just musing) I appeciate your prompt reply onpnt
 
Thanks Jonax!!! works great you get a star.
 
Where do you want radio-button, and what should th eoptions be? This is not a bug - it's an undocumented feature...
;-)
 
Thx ;) This is not a bug - it's an undocumented feature...
;-)
 
I'd like the radio buttons to diplay with the order so that if if the user want to order more he will check the yes button and if not check the no button. thereby palcing the order to a text file. I'm working on that now the asp for input was my main problem and you've given more than enough to solve it. Thanks again Jonax
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top