永发信息网

vb编写一个简单的计算机程序

答案:2  悬赏:0  手机版
解决时间 2021-12-17 23:08
以下代码错在哪里?
<html>
<head><title>计算器</title>
<script language="vbscript">
sub button1_onclick()
dim name1,name2,name3
if myform.option.value="+" then
myform.name3.value=name1.value+name2.value
else if myform.option="-" then
myform.name3.value=name1.value-name2.value
else if myform.option="*" then
myform.name3.value=name1.value*name2.value
else if myform.option="/" then
myform.name3.value=name1.value/name2.value
end if
end if
end if
end sub
</script></head>
<body>
<form name="myform">
数字:<input type="text" name="name1">
符号:<select><option>+</option><option>-</option><option>*</option>
<option>/</option></select>
数字:<input type="text" name="name2">
<input type="button" name="button1" value="等于">
<input type="text" name="name3">
<input type="reset" value="重置">
</form>
</body>
</html>
最佳答案
值不能这样加的吧,应该要把它写进cint()的函数里,就是cint(name1.value)+cint(name2.value )
全部回答
给你了,有问题再联系吧 
总共有0~9 .(小数点)+ - * / = 和c(删除)17个按钮与一个label(输出) 
option explicit 

private storedvalue as double 

private const opnone = 0 
private const opadd = 1 
private const opsubtract = 2 
private const opmultiply = 3 
private const opdivide = 4 
private operator as integer 

private newentry as boolean 

'删除最后的字符 
private sub deletecharacter() 
dim txt as string 
dim min_len as integer 

txt = txtdisplay.text 
if left$(txt, 1) = "-" then 
min_len = 2 
else 
min_len = 1 
end if 

if len(txt) > min_len then 
txtdisplay.text = left$(txt, len(txt) - 1) 
else 
txtdisplay.text = "0" 
end if 
end sub 

'清除显示内容,保存运算符 
private sub cmdclear_click() 
cmdclearentry_click 
storedvalue = 0 
operator = opnone 
end sub 

'清除显示内容 
private sub cmdclearentry_click() 
txtdisplay.text = "" 
end sub 

' 显示小数点 
private sub cmddecimal_click() 
if instr(txtdisplay.text, ".") then 
beep 
else 
if newentry then 
txtdisplay.text = "." 
newentry = false 
else 
txtdisplay.text = txtdisplay.text & "." 
end if 
end if 
end sub 

'计算上一操作符的运算结果 
private sub cmdequals_click() 
dim new_value as double 

if txtdisplay.text = "" then 
new_value = 0 
else 
new_value = cdbl(txtdisplay.text) 
end if 
select case operator 
case opnone 
storedvalue = new_value 
case opadd 
storedvalue = storedvalue + new_value 
case opsubtract 
storedvalue = storedvalue - new_value 
case opmultiply 
storedvalue = storedvalue * new_value 
case opdivide 
storedvalue = storedvalue / new_value 
end select 
operator = opnone 
newentry = true 
txtdisplay.text = format$(storedvalue) 
end sub 

' 显示数字 
private sub cmdnumber_click(index as integer) 
if newentry then 
txtdisplay.text = format$(index) 
newentry = false 
else 
txtdisplay.text = txtdisplay.text & format$(index) 
end if 
end sub 

private sub cmdoperator_click(index as integer) 
cmdequals_click 
operator = index 
newentry = true 
end sub 
'改变符号 
private sub cmdplusminus_click() 
if newentry then 
txtdisplay.text = "-" 
elseif left$(txtdisplay.text, 1) = "-" then 
txtdisplay.text = right$(txtdisplay.text, 2) 
else 
txtdisplay.text = "-" & txtdisplay.text 
end if 
end sub 

'处理键盘按键 
private sub form_keypress(keyascii as integer) 
txtdisplay_keypress keyascii 
end sub 

private sub form_keyup(keycode as integer, shift as integer) 
txtdisplay_keyup keycode, shift 
end sub 

private sub txtdisplay_change() 
txtdisplay.selstart = len(txtdisplay.text) 
end sub 

private sub txtdisplay_gotfocus() 
txtdisplay_change 
end sub 


private sub txtdisplay_keypress(keyascii as integer) 
dim ch as string 

ch = chr$(keyascii) 
select case ch 
case "0" 
cmdnumber_click 0 
case "1" 
cmdnumber_click 1 
case "2" 
cmdnumber_click 2 
case "3" 
cmdnumber_click 3 
case "4" 
cmdnumber_click 4 
case "5" 
cmdnumber_click 5 
case "6" 
cmdnumber_click 6 
case "7" 
cmdnumber_click 7 
case "8" 
cmdnumber_click 8 
case "9" 
cmdnumber_click 9 
case "*", "x", "x" 
cmdoperator_click opmultiply 
case "+" 
cmdoperator_click opadd 
case vbcrlf, vbcr, "=" 
cmdequals_click 
case "-" 
cmdoperator_click opsubtract 
case "." 
cmddecimal_click 
case "/" 
cmdoperator_click opdivide 
case "c", "c" 
cmdclearentry_click 
end select 

keyascii = 0 
end sub 

private sub txtdisplay_keyup(keycode as integer, shift as integer) 
select case keycode 
case vbkeynumpad0 
cmdnumber_click 0 
case vbkeynumpad1 
cmdnumber_click 1 
case vbkeynumpad2 
cmdnumber_click 2 
case vbkeynumpad3 
cmdnumber_click 3 
case vbkeynumpad4 
cmdnumber_click 4 
case vbkeynumpad5 
cmdnumber_click 5 
case vbkeynumpad6 
cmdnumber_click 6 
case vbkeynumpad7 
cmdnumber_click 7 
case vbkeynumpad8 
cmdnumber_click 8 
case vbkeynumpad9 
cmdnumber_click 9 
case vbkeymultiply 
cmdoperator_click opmultiply 
case vbkeyadd 
cmdoperator_click opadd 
case vbkeyseparator 
cmdequals_click 
case vbkeysubtract 
cmdoperator_click opsubtract 
case vbkeydecimal 
cmddecimal_click 
case vbkeydivide 
cmdoperator_click opdivide 
case vbkeyback, vbkeydelete 
deletecharacter 
end select 
keycode = 0 
end sub

还有前台代码:
<%@ page language="vb" autoeventwireup="false" codefile="jsq.aspx.vb" inherits="luo_jsq" %>

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
 <title>untitled page</title>
</head>
<body>
 <form id="form1" runat="server">
 <div>
 <asp:button id="button1" runat="server" text="1" width="67px" />
 <asp:button id="button2" runat="server" text="2" width="86px" />
 <asp:button id="button3" runat="server" text="3" width="132px" />
 <asp:button id="button4" runat="server" text="+" width="90px" /><br />
 <asp:button id="button5" runat="server" text="4" width="67px" />
 <asp:button id="button6" runat="server" text="5" width="86px" height="24px" />
 <asp:button id="button7" runat="server" text="6" width="132px" />
 <asp:button id="button8" runat="server" text="-" width="90px" /><br />
 <asp:button id="button11" runat="server" text="7" width="67px" />
 <asp:button id="button9" runat="server" text="8" width="86px" />
 <asp:button id="button10" runat="server" text="9" width="132px" />
 <asp:button id="button13" runat="server" text="*" width="90px" /><br />
 <asp:button id="button12" runat="server" text="0" width="67px" /> <asp:button
 id="button15" runat="server" text="." width="86px" /> <asp:button id="button16"
 runat="server" text="=" width="132px" />
 <asp:button id="button14" runat="server" text="/" width="90px" /><br />
 <asp:textbox id="textbox1" runat="server"></asp:textbox></div>
 </form>
</body>
</html>
不同的vb软件可能有兼容问题,我用的是微软的visual studio
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
红砂坝森林派出所在什么地方啊,我要处理点事
北京牌子货车限行尾号走五环怎么去新发地
土贵乌拉镇北派出所地址有知道的么?有点事想
天皮山冶金化工园区派出所办公位置在哪啊?好
兴和县森林公安分局国道生态区派出所位置在什
如何在聚尚美品网页上面注入自己的代理信息
高考体检转氨酶高,复检要查什么项目
科布尔镇第二派出所地址有知道的么?有点事想
刑事案件当事人如何阅卷
一台子派出所办公地址在什么地方?我要处理点
台基庙派出所办公位置在哪啊?好找么?
离职一年多,没有办离职手续,可以到下一家单
一只鸡一男人头像
日立HCP-6680X开机时power和temp指示灯闪红灯
一个丽下面一个鹿念什么
推荐资讯
怎么向老师请假,老师才会信
请问在重庆开州区有什么快递可加盟的
单选题“先定事,后定人,以事选人,选人干事
北京市国土资源局通州分局(梨园北街)地址在什
世界上最大的宗教是A.基督教B.佛教C.道教
单选题下列行为中,最有助于提高审美能力的是
衡量一个国家综合经济实力重要标志的工业部门
2011年是《劳动合同法》实施三周年。劳动者维
泰安10吨吊车价格
k1629列车长在7号车厢?我订的7号车厢的3334
英国阿伯泰邓迪大学在国内好不好就业
1从南京到通辽坐火车要多长时间?
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?