以下代码错在哪里?
<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>
vb编写一个简单的计算机程序
答案:2 悬赏:0 手机版
解决时间 2021-12-17 23:08
- 提问者网友:富士山上尢
- 2021-12-17 15:37
最佳答案
- 五星知识达人网友:轻熟杀无赦
- 2021-12-17 16:36
值不能这样加的吧,应该要把它写进cint()的函数里,就是cint(name1.value)+cint(name2.value )
全部回答
- 1楼网友:躲不过心动
- 2021-12-17 17:57
给你了,有问题再联系吧 总共有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
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯