您的位置:程序门 -> vb -> 基础类



小弟刚学vb,编个计算器程序!可是有个问题!希望各位大侠帮忙!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


小弟刚学vb,编个计算器程序!可是有个问题!希望各位大侠帮忙!
发表于:2008-01-20 09:32:38 楼主
数字计算完以后,在点1的按钮,就接着连着计算后的数!这怎么解决啊!?
以下是我部分代码
dim   a   as   integer
dim   b   as   integer
dim   c   as   string
dim   x   as   integer

private   sub   a0_click(index   as   integer)
if   x   =   1   then
    text1.text   =   "0"
      if   text1.text   =   ""   then
            text1.text   =   text1.text   &   "0"
          exit   sub
    end   if
end   if
text1.text   =   text1.text   &   "0"
end   sub

private   sub   a1_click(index   as   integer)
if   x   =   1   then
  text1.text   =   ""
  end   if
if   x   =   1   and   text1.text   =   ""   then
            text1.text   =   text1.text   &   "1"
      end   if
          text1.text   =   text1.text   &   "1"
end   sub

private   sub   a2_click(index   as   integer)
if   x   =   1   then
    text1.text   =   "2"
    end   if
      if   text1.text   <>   ""   then
            text1.text   =   "   "
            text1.text   =   text1.text   &   "2"
            end   if

text1.text   =   text1.text   &   "2"
end   sub

private   sub   a3_click(index   as   integer)
x   =   true
text1.text   =   text1.text   &   "3"
end   sub

private   sub   a4_click(index   as   integer)
text1.text   =   text1.text   &   "4"
end   sub

private   sub   a5_click(index   as   integer)

text1.text   =   text1.text   &   "5"
end   sub

private   sub   a6_click(index   as   integer)

text1.text   =   text1.text   &   "6"
end   sub

private   sub   a7_click(index   as   integer)

text1.text   =   text1.text   &   "7"
end   sub

private   sub   a8_click(index   as   integer)

text1.text   =   text1.text   &   "8"
end   sub

private   sub   a9_click(index   as   integer)

text1.text   =   text1.text   &   "9"
end   sub

private   sub   b1_click(index   as   integer)
a   =   val(text1.text)
b   =   1
text1.text   =   ""
end   sub

private   sub   b2_click(index   as   integer)
a   =   val(text1.text)
b   =   2
text1.text   =   ""

end   sub

private   sub   b3_click(index   as   integer)
a   =   val(text1.text)
b   =   3
text1.text   =   ""
end   sub

private   sub   b4_click(index   as   integer)
a   =   val(text1.text)
b   =   4
text1.text   =   ""
end   sub

private   sub   b5_click()
select   case   b
case   1
c   =   str(a   +   val(text1.text))
x   =   1
case   2
c   =   str(a   -   val(text1.text))
case   3
c   =   str(a   *   val(text1.text))
case   4
if   text1.text   =   "0"   then
      msgbox   "除数不能为零!"
      else
text1.text   =   str(a   /   val(text1.text))
end   if
case   else
text1.text   =   ""
end   select
text1.text   =   c
end   sub

private   sub   return_click(index   as   integer)
text1.text   =   "0"
end   sub

private   sub   start_click(index   as   integer)
end
end   sub


private   sub   text1_change()
text1.text   =   val(text1.text)


end   sub
发表于:2008-01-20 09:50:321楼 得分:0
不明白楼主的意思
发表于:2008-01-20 19:35:492楼 得分:0
我也没看明白...
发表于:2008-01-21 08:32:253楼 得分:0
变量名控件名全部是abc……

按下1以后把text1.text=""便是了
发表于:2008-01-21 11:43:344楼 得分:0
=====cike例题=====
name   =   4句代码的计算器
form   =   3个text   1个command   4个option
设置:
1\3个text的值清空  
2\4个option的标题分别为"+-*/"   [option1=+   option2=-   ...4=/]
3\command的标题为"="  
4\位置排序:   text1   下面   有4个   option   再下面是text2   再下面是   command   最下面是text3
效果:运行后可以是个简单的计算器...
==================
代码:
vbscript code
private sub command1_click() if option1 then text3 = val(text1) + val(text2) if option2 then text3 = val(text1) - val(text2) if option3 then text3 = val(text1) * val(text2) if option4 and val(text2) <> 0 then text3 = val(text1) / val(text2) end sub


快速检索

最新资讯
热门点击