在窗体上放置两个CommandButton,分别为Command1和Command2,代码如下:
Dim Die As Long, Zhi As Long
Private Sub Command1_Click()
Dim x As Long, y As Long
x = Val(InputBox("请输入底数:", "输入", "0"))
y = Val(InputBox("请输入指数:", "输入", "1"))
If x > 0 And y > 0 Then
Die = x
Zhi = y
Command2.Enabled = True
Else
Command2.Enabled = False
End If
End Sub
Private Sub Command2_Click()
MsgBox CStr(Die) & " 的 " & CStr(Zhi) & " 次幂的结果为:" & CStr(Die ^ Zhi), vbInformation, "计算结果"
End Sub
Private Sub Form_Load()
Command1.Caption = "输入(&I)"
Command2.Caption = "计算(&C)"
End Sub