| 发表于: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 |
|
|
|
|