输入框按取消自动退出

来源:百度知道 编辑:UC知道 时间:2024/05/29 05:15:30
Dim a As Integer, b As Integer, c As Integer, d As Integer, e As Integer, f As Integer, g As Integer

Private Sub Command1_Click()

a = InputBox("外销美元价格")
b = InputBox("汇率")
d = InputBox("毛利成本")
e = InputBox("退税率")
MsgBox "您所要的毛利=" & a * b - d / 1.17 * (1 + 17 - e)
End Sub

Private Sub Command2_Click()
a = InputBox("外销美元价格")
b = InputBox("汇率")
c = InputBox("毛利")

MsgBox "您所要的毛利率=" & c / (a * b)
End Sub

Private Sub Command3_Click()
d = InputBox("毛利成本")
g = InputBox("毛利率")
MsgBox "您所要的内销价格=" & d / 1.17 / (1 - g) * 1.17 & "(含税价格)"
End Sub

Private Sub Command4_Click()
Unload Me

End Sub
Public Sub Form_Load()

End Sub

问题是可以解决的
用STRPTR函数
比如
dim val as string
int=strptr(inputbox("please input a number"))
if val=0 then
'按取消时
msgbox "you click cancel!"
else
'按确定时
if isnumeric(val)=fale then
msgbox "it is not a number!"
else
msgbox "input correct!"
end if
end if

建议使用TextBox代替InputBox输入.

InputBox返回的值传给Integer变量,如果为空或不为数字时就会出现错误。而用TextBox则可以很好的控制变量的类型。