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



我做了个计算器,有点问题,请大虾们帮一下,谢谢


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


我做了个计算器,有点问题,请大虾们帮一下,谢谢
发表于:2007-03-30 14:45:35 楼主
我的计算器有以下几个不足之处:
1,用键盘输入时,相应的按钮不能变成按下的样子.
2,键盘输入和鼠标点击时,光标不能总是停在最右边一位,从而使输入有误
3,不知道如何隐藏文本框中的光标.
4,文本框不是只读的.
控件属性设置和代码如下:
dim   operand1   as   double,   operand2   as   double
dim   operator   as   string
dim   cleardisplay   as   boolean

private   sub   digits_click(index   as   integer)
      if   cleardisplay   then
            display.caption   =   " "
            cleardisplay   =   false
      end   if
      display.caption   =   display.caption   &   digits(index).caption
end   sub


private   sub   dotbttn_click()
    if   instr(display.caption,   ". ")   then
        exit   sub
    else
        display.caption   =   display.caption   +   ". "
    end   if
end   sub


private   sub   form_load()

end   sub

'运算符
private   sub   plus_click()
    operand1   =   val(display.caption)
    operator   =   "+ "
    display.caption   =   "   "
end   sub
private   sub   minus_click()
        operand1   =   val(diplay.caption)
        operator   =   "- "
        display.caption   =   "   "
end   sub
private   sub   times_click()
        operand1   =   val(diplay.caption)
        operator   =   "* "
        display.caption   =   "   "
end   sub
private   sub   div_click()
        operand1   =   val(diplay.caption)
        operator   =   "/ "
        display.caption   =   "   "
end   sub

'等号按钮
private   sub   equals_click()
        dim   result   as   double
        on   error   goto   errorhandler
        operand2   =   val(display.caption)
        if   operator   =   "+ "   then   result   =   operand1   +   operand2
        if   operator   =   "- "   then   result   =   operand1   -   operand2
        if   operator   =   "* "   then   result   =   operand1   *   operand2
        if   operator   =   "/ "   and   operand2   <>   0   then   result   =   operand1   /   operand2
        display.caption   =   result
        cleardisplay   =   true
goto   endsub
errorhandler:
        msgbox   "此操作产生如下错误: "   &   vbcrlf   &   err.descriprion
        display.caption   =   "error "
        cleardisplay   =   true
endsub:
end   sub

'正负数按钮:
private   sub   plusminus_click()
        display.caption   =   -val(display.caption)
end   sub

'倒数按钮
private   sub   over_click()
        if   val(display.caption)   <>   0   then   display.caption   =   1   /   val(display.caption)
end   sub

'清除按钮:
private   sub   clear_click()
        display.caption   =   "   "
end   sub

发表于:2007-03-30 14:56:051楼 得分:0
1,用键盘输入时,相应的按钮不能变成按下的样子.     用checkbox,style设置一下
2,键盘输入和鼠标点击时,光标不能总是停在最右边一位,从而使输入有误,//不理解你说得输入有误
3,不知道如何隐藏文本框中的光标.                                                 //enable=false就没光标了
4,文本框不是只读的.     //文本框设置成只读
发表于:2007-04-01 10:16:442楼 得分:0
谢谢这位大虾,我说的光标不能总在最后是这样的:比如你用键盘输入111,然后用鼠标输入222,结果是111222,再用键盘输入333,就会成了333111222,是这个意思,不知道我的表达清楚不?
enable=false那文本框不是要不见了??


快速检索

最新资讯
热门点击