VB做加减乘除的代码是什么?

如题所述

第1个回答  2022-11-16
代码如下 \x0d\x0a'已增加操作数正确性验证及 除数不能为0验证 \x0d\x0a\x0d\x0aPrivate Sub Command1_Click() \x0d\x0aIf IsNumeric(Text1.Text) And Text1.Text <> "" And IsNumeric(Text2.Text) And Text2.Text <> "" Then \x0d\x0aSelect Case Combo1.ListIndex \x0d\x0aCase 0 \x0d\x0aText3.Text = Val(Text1.Text) + Val(Text2.Text) \x0d\x0aCase 1 \x0d\x0aText3.Text = Val(Text1.Text) - Val(Text2.Text) \x0d\x0aCase 2 \x0d\x0aText3.Text = Val(Text1.Text) * Val(Text2.Text) \x0d\x0aCase 3 \x0d\x0aIf Val(Text1.Text) <> 0 Then \x0d\x0aText3.Text = Val(Text1.Text) / Val(Text2.Text) \x0d\x0aElse \x0d\x0aMsgBox "除数不能为0", , "错误" \x0d\x0aEnd If \x0d\x0aEnd Select \x0d\x0aElse \x0d\x0aMsgBox "请输入操作数", , "错误" \x0d\x0aEnd If \x0d\x0aEnd Sub \x0d\x0a\x0d\x0aPrivate Sub Form_Load() \x0d\x0aCombo1.AddItem "+" \x0d\x0aCombo1.AddItem "-" \x0d\x0aCombo1.AddItem "*" \x0d\x0aCombo1.AddItem "/" \x0d\x0aCombo1.ListIndex = 0 \x0d\x0aText1.Text = "" \x0d\x0aText2.Text = "" \x0d\x0aText3.Text = "" \x0d\x0aCommand1.Caption = "计算" \x0d\x0a\x0d\x0aEnd Sub

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网