如题所述
第1个回答 2022-12-11
控件 名称 Caption 控件 名称 Caption \x0d\x0a窗体 Form 1 计算器 \x0d\x0a按钮 Command 1(0)~Command1(9) Caption 0 ~ 9 \x0d\x0a按钮 Command6(0) + \x0d\x0a按钮 Command 6(1) - \x0d\x0a按钮 Command 6(2) *\x0d\x0a按钮 Command 6(3) /\x0d\x0a按钮 Command 2 退格 \x0d\x0a按钮 Command 3 清除\x0d\x0a按钮 Command 4 .\x0d\x0a按钮 Command 5 = \x0d\x0a\x0d\x0aDim shu1 As Single, shu2 As Single, suanfu As String\x0d\x0a'定义两个单精度数变量用与存放参与运算的数,一个字符型存放运算符\x0d\x0a\x0d\x0aPrivate Sub Command1_Click(Index As Integer)\x0d\x0aText1.Text = Text1.Text & Command1(Index).Caption\x0d\x0a'将command1的单击事件与文本框显示的内容连接\x0d\x0a\x0d\x0aEnd Sub\x0d\x0aPrivate Sub Command2_Click() '假如输入错误,可每次退后一格\x0d\x0aIf Text1.Text = "" Then\x0d\x0aExit Sub\x0d\x0aEnd If\x0d\x0aText1.Text = Left(Text1.Text, Len(Text1.Text) - 1)\x0d\x0aEnd Sub\x0d\x0aPrivate Sub Command3_Click()\x0d\x0a Text1.Text = "" '清除\x0d\x0aEnd Sub\x0d\x0aPrivate Sub Command4_Click()\x0d\x0aText1.Text = Text1.Text + "."\x0d\x0aIf (InStr(Text1.Text, ".") = 1) Then '第一位不能为小数\x0d\x0a Text1.Text = ""\x0d\x0aEnd If\x0d\x0a\x0d\x0aIf InStr(Text1.Text, ".") < Len(Text1.Text) Then '防止出现两个小数点\x0d\x0aText1.Text = Left(Text1.Text, Len(Text1.Text) - 1)\x0d\x0aEnd If\x0d\x0a\x0d\x0aEnd Sub\x0d\x0a\x0d\x0aPrivate Sub Command5_Click() '开始加减乘除的运算\x0d\x0ashu2 = Val(Text1.Text)\x0d\x0a Select Case suanfu\x0d\x0a Case "+"\x0d\x0a Text1.Text = shu1 + shu2\x0d\x0a Case "-"\x0d\x0a Text1.Text = shu1 - shu2\x0d\x0a Case "*"\x0d\x0a Text1.Text = shu1 * shu2\x0d\x0a Case "/"\x0d\x0a If shu2 = 0 Then\x0d\x0a Text1.Text = "被除数不可为0"\x0d\x0a Else\x0d\x0a Text1.Text = shu1 / shu2\x0d\x0a End If\x0d\x0a End Select\x0d\x0aEnd Sub\x0d\x0a\x0d\x0aPrivate Sub Command6_Click(Index As Integer)\x0d\x0ashu1 = Val(Text1.Text) '将shu1隐藏起来\x0d\x0a suanfu = Command6(Index).Caption\x0d\x0a Text1.Text = ""\x0d\x0aEnd Sub