当前位置:编程学习 > VB >>

谁会Vb做计算器

老师要求0-9都是Command1 .+-*/都是COMMAND2 望高手帮帮我
答案:Option Explicit
Dim counta As Double, countb As Double, sum As String, bl As Boolean

Private Sub Command1_Click(Index As Integer)
If bl = True Then
Text1.Text = ""
bl = False
End If
Text1.Text = Text1.Text + Command1(Index).Caption
End Sub

Private Sub Command2_Click(Index As Integer)
If Text1.Text = "" Then
MsgBox "请输入数值后再点击此符号!谢谢!", , "提示"
Exit Sub
Else
counta = Val(Text1.Text)
sum = Command2(Index).Caption
Text1.Text = ""
End If
 End Sub
Private Sub Command3_Click()
bl = True
If Text1.Text = "" Then
MsgBox "请输入数值再点击!谢谢!", , "提示"
Exit Sub
Else
countb = Val(Text1.Text)
Select Case sum
  Case "+"
     Text1.Text = Str(counta + countb)
     Case "-"
     Text1.Text = Str(counta - countb)
     Case "*"
     Text1.Text = Str(counta * countb)
     Case "/"
     If Text1.Text = "0" Then
     MsgBox "除数不能为零", vbCritical, "出错提示"
     Text1.Text = ""
     Text1.SetFocus
     Else
     Text1.Text = Str(counta / countb)
     End If
End Select
     End If
     End Sub
Private Sub Command4_Click()
Text1.Text = ""
End Sub

Private Sub Command5_Click()
End
End Sub

Private Sub Form_Unload(Cancel As Integer) '卸载窗体事件
MsgBox "程序中内容均有自己完成,现在才发现编程是那么的不容易!此程序还不完善!但也算一个半成品吧!邮箱:zhangleizhb@sogou.com QQ:909507090 谢谢!", , "提示"
End Sub

 


Private Sub mnuban_Click()
MsgBox "版本v1.2", , "提示"
End Sub

Private Sub mnubule_Click()
Form1.BackColor = vbBlue
End Sub

Private Sub mnuexit_Click()
End
End Sub


Private Sub mnuhelp_Click()
MsgBox "对不起!程序简单没有帮助!", , "提示"
End Sub

Private Sub mnured_Click()
Form1.BackColor = vbRed
End Sub

Private Sub mnuzhe_Click()
MsgBox "地狱黑雪!QQ:909507090", , "提示"

End Sub

Private Sub Timer1_Timer()
    If Label2.Left + Label2.Width <= 0 Then
        Label2.Left = Label2.Width
    Else
        Label2.Left = Label2.Left - 1
    End If
End Sub
Private Sub Form_load()
Label2.ForeColor = vbRed
Timer1.Interval = 1
bl = False
End Sub

 

去找MSDN 的VB 例程参考好不好啊? 求人不如求己!这个可以下载安装MSDN得到的!

上一个:VB中Drag方法如何使用?
下一个:VB怎么显示TIF格式图片?

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,