บวกเลขในAsp ใช้ยังงี้นะครับ ลองเอาไปใช้ดูนะ
<form action="calcu.asp" method="get" name="fm1">
ตัวเลขตัวที่1 : <input name="num1" type="text" size="30"> <br>
ตัวเลขตัวที่2 : <input name="num2" type="text" size="30"> <br>
<input name= "บวกเลข" type="submit">
</form>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<%
x = request.querystring("num1")
y = request.querystring("num2")
if x <> "" and y <> "" then
sum = addnumber(x,y)
response.write x & " + " & y & " = " & sum
end if
function addnumber(a, b)
a = replace(a,",","")
b = replace(b,",","")
pos1 = instrrev(a,".")
pos2 = instrrev(b,".")
a1 = left(mid(a,pos1+1,len(a)-pos1) & "00",2)
b1 = left( mid(b,pos2+1,len(b)-pos2) & "00",2)
if len(sumdecimal) > 2 then
sub1 = right(sumdecimal,2)
sub2 = mid(sumdecimal,1,len(sumdecimal)-2)
else
if len(sumdecimal) <=1 then
sub1 = right("00" & sumdecimal,2)
else
sub1 = sumdecimal
end if
sub2 = 0
end if
total1 = int(nodeci1) + int(nodeci2)
total2 = total1 + int(sub2)
total3 = formatnumber(total2,0) & "." & sub1
addnumber = total3
end function
%>
Date :
11 Jul 2546 16:38:42
By :
tttt
No. 2
Guest
แก้ไขครับผม
<form action="calcu.asp" method="get" name="fm1">
ตัวเลขตัวที่1 : <input name="num1" type="text" size="30"> <br>
ตัวเลขตัวที่2 : <input name="num2" type="text" size="30"> <br>
<input name= "บวกเลข" type="submit">
</form>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<%
x = request.querystring("num1")
y = request.querystring("num2")
if x <> "" and y <> "" then
sum = addnumber(x,y)
response.write x & " + " & y & " = " & sum
end if
function addnumber(a, b)
a = replace(a,",","")
b = replace(b,",","")
pos1 = instrrev(a,".")
pos2 = instrrev(b,".")
if pos1 > 0 then
a1 = left(mid(a,pos1+1,len(a)-pos1) & "00",2)
else
a1 = 0
end if
if pos2 > 0 then
b1 = left( mid(b,pos2+1,len(b)-pos2) & "00",2)
else
b1 = 0
end if
sumdecimal = int(a1) +int(b1)
if pos1 > 0 then
nodeci1 = mid(a,1,pos1-1)
else
nodeci1 = a
end if
if pon2 > 0 then
nodeci2 = mid(b,1,pos2-1)
else
nodeci2 = b
end if
if len(sumdecimal) > 2 then
sub1 = right(sumdecimal,2)
sub2 = mid(sumdecimal,1,len(sumdecimal)-2)
else
if len(sumdecimal) <=1 then
sub1 = right("00" & sumdecimal,2)
else
sub1 = sumdecimal
end if
sub2 = 0
end if
total1 = int(nodeci1) + int(nodeci2)
total2 = total1 + int(sub2)
total3 = formatnumber(total2,0) & "." & sub1
addnumber = total3
end function
%>