求用VB编写一个简单计算器

[复制链接]
查看11 | 回复4 | 2008-2-23 20:42:25 | 显示全部楼层 |阅读模式
vb6。0 从入门到精通 一书里有代码别人都写好了,你忙什么嘛
回复

使用道具 举报

千问 | 2008-2-23 20:42:25 | 显示全部楼层
这个我也自己编写过你可以去http://hi.baidu.com/xnzhrx 这里查看资料
回复

使用道具 举报

千问 | 2008-2-23 20:42:25 | 显示全部楼层
http://hi.baidu.com/xnzhrx有现成的代码和界面设计
回复

使用道具 举报

千问 | 2008-2-23 20:42:25 | 显示全部楼层
只用一个文本框,也很简单啊利用控件数组 控件拖四个按所钮 一个文本框 并把COMMAND1 和COMMAND3 的 INDEX属性改为0 ,不然会出错 Dim sign, flag, a, b As Long '标记输入的数字 Private Sub Command1_Click(Index As Integer) '运算符 flag = Index If IsNumeric(Text1.Text) Then If sign = 0 Then a = CLng(Text1.Text) ElseIf sign = 1 Then MsgBox "错误操作" End If Else: MsgBox "输入错误": sign = 0 End If Text1.Text = "" sign = 1 End Sub Private Sub Command2_Click() '计算结果 If IsNumeric(Text1.Text) And sign = 1 Then b = CLng(Text1.Text) If flag = 0 Then Text1.Text = CStr(a + b) ElseIf flag = 1 Then Text1.Text = CStr(a - b) ElseIf flag = 2 Then Text1.Text = CStr(a * b) ElseIf flag = 3 Then Text1.Text = CStr(a / b) End If sign = 0 Else: MsgBox "错误操作,重新输入": sign = 0 End If End Sub Private Sub Command3_Click(Index As Integer) Text1.Text = Text1.Text & Index End Sub Private Sub Command4_Click() '清空结果 Text1.Text = "" sign = 0 End Sub Private Sub Form_Load() Form1.Width = 250 * 15 Form1.Height = 400 * 15 Form1.ScaleMode = 3 Text1.Left = 30 Text1.Text = "" Text1.Top = 20 Text1.Width = 150 Text1.Height = 30 '--------------------------------------- Command3(0).Caption = "0" Command3(0).Top = Text1.Top + 50 Command3(0).Left = 10 Command3(0).Width = 40 Command3(0).Height = 30 For i = 1 To 9 Load Command3(i) With Command3(i) Command3(i).Caption = Str(i) Command3(i).Left = Command3(i - 1).Left + 50 If i > 3 Then Command3(i).Left = Command3(0).Left + (Command3(0).Width + 10) * (i Mod 4) Command3(i).Top = Command3(0).Top + (Command3(0).Height + 10) * (i \ 4) End If Command3(i).Visible = True End With Next Command1(0).Left = 10 Command1(0).Top = Text1.Top + 200 Command1(0).Width = 40 Command1(0).Height = 30 For i = 1 To 3 Load Command1(i) With Command1(i) Command1(i).Visible = True Command1(i).Left = Command1(i - 1).Left + Command1(i - 1).Width + 10 End With Next Command1(0).Caption = "+" Command1(1).Caption = "-" Command1(2).Caption = "*" Command1(3).Caption = "/" Command2.Top = Text1.Top + 250 Command2.Visible = True Command2.Left = 100 Command2.Caption = "=" Command4.Caption = "清空结果" Command4.Top = Command2.Top Command4.Left = 20 End Sub
回复

使用道具 举报

千问 | 2008-2-23 20:42:25 | 显示全部楼层
Private Sub Command1_Click()Text3.Text = Val(Text1.Text) + Val(Text2.Text)Label1.Caption = "+"End SubPrivate Sub Command2_Click()Text3.Text = Val(Text1.Text) - Val(Text2.Text)Label1.Caption = "-"End SubPrivate Sub Command3_Click()Text3.Text = Val(Text1.Text) * Val(Text2.Text)Label1.Caption = "*"End SubPrivate Sub Command4_Click()Text3.Text = Val(Text1.Text) \ Val(Text2.Text)Label1.Caption = "\"End SubPrivate Sub Command5_Click()Text1.Text = 0Text2.Text = 0Text3.Text = 0End Sub
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行