0-9建立的是一个按钮数组,代码如下,请指教加入怎么样的代码可以从键盘输入相应的数字?
代码:
Option Explicit
Dim Operand1 As Double, Operand2 As Double
Dim Operator As String
Dim ClearDisplay As BooleanPrivate Sub ClearBttn_Click()
   Display.Caption = ""
End SubPrivate Sub Digits_Click(Index As Integer)
   If ClearDisplay Then
      Display.Caption = ""
      ClearDisplay = False
   End If
   Display.Caption = Display.Caption + Digits(Index).Caption
End SubPrivate Sub Div_Click()
Operand1 = Val(Display.Caption)
Operator = "/"
Display.Caption = ""
End SubPrivate Sub DotBttn_Click()
   If InStr(Display.Caption, ".") Then
      Exit Sub
   Else
      Display.Caption = Display.Caption + "."
   End If
End SubPrivate Sub Equals_Click()
Dim result As DoubleOn 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
   Exit Sub
ErrorHandler:
   MsgBox "The operation resulted in the following error" & vbCrLf & Err.Description
   Display.Caption = "ERROR"
   ClearDisplay = True
End SubPrivate Sub Minus_Click()
Operand1 = Val(Display.Caption)
Operator = "-"
Display.Caption = ""
End SubPrivate Sub Over_Click()
   If Val(Display.Caption) <> 0 Then Display.Caption = 1 / Val(Display.Caption)
End SubPrivate Sub Plus_Click()
Operand1 = Val(Display.Caption)
Operator = "+"
Display.Caption = ""
End SubPrivate Sub PlusMinus_Click()
   Display.Caption = -Val(Display.Caption)
End SubPrivate Sub Times_Click()
Operand1 = Val(Display.Caption)
Operator = "*"
Display.Caption = ""
End Sub

解决方案 »

  1.   

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Const WM_SETHOTKEY = &H32
    Private Const HOTKEYF_SHIFT = &H1
    Private Const HOTKEYF_CONTROL = &H2
    Private Const HOTKEYF_ALT = &H4Private Sub Form_Load()
       '这个程序将Form的HotKey设置为 Ctl+Alt+A
       Dim l As Long
       Dim wHotkey As Long
       wHotkey = (HOTKEYF_ALT Or HOTKEYF_CONTROL) * (2 ^ 8) + 65
       l = SendMessage(Me.hwnd, WM_SETHOTKEY, wHotkey, 0)
    End Sub
      

  2.   

    加了,好像还是不可以啊!你做的这个热键Ctl+Alt+A,在xp操作系统中应该是截图的热键,只要按下去,就会出来菜单,让选择截图范围!
      

  3.   

    用keydown,keyup或keypress事件
    然后用keycode或keyascii来确定按了什么键,因为不同的键对应不同的keycode或keyascii值。对不同的值做对应的处理即可。
      

  4.   

    将文本框的ReadOnly设为True就可
      

  5.   

    //你做的这个热键Ctl+Alt+A,在xp操作系统中应该是截图的热键,只要按下去,就会出来菜单,让选择截图范围我倒,关掉QQ!
      

  6.   

    //你做的这个热键Ctl+Alt+A,在xp操作系统中应该是截图的热键,只要按下去,就会出来菜单,让选择截图范围我倒,关掉QQ!
    我关掉QQ了,但是按了以后没有效果啊!
    将文本框的ReadOnly设为True就可-------我的计算器显示处用的是lable控件,故而应该不存在那个Readonly属性。
    text1.lock=true------同上按钮建议用控件数组处理------可以告诉我这个处理方法吗?给个程序也行啊,谢谢!还请各位继续赐教!