如何用VB做一个简单计算器 要求实现加减乘除乘方开方功能 用0~9按钮实现 类似WINDOWS系统自带的计算器 最好带图
来源:学生作业帮 编辑:灵鹊做题网作业帮 分类:综合作业 时间:2024/05/16 02:31:34
如何用VB做一个简单计算器 要求实现加减乘除乘方开方功能 用0~9按钮实现 类似WINDOWS系统自带的计算器 最好带图
最好有声明 代码太多 看着晃~
最好有声明 代码太多 看着晃~
用记事本把这段代码复制过去,然后另存为.frm就可以了VERSION 5.00Begin VB.Form frmMain Appearance = 0 'Flat BackColor = &H80000005& BorderStyle = 3 'Fixed Dialog Caption = "简单计算器" ClientHeight = 2430 ClientLeft = 45 ClientTop = 435 ClientWidth = 3150 KeyPreview = -1 'True LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 2430 ScaleWidth = 3150 ShowInTaskbar = 0 'False StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Command10 Caption = "^" Height = 375 Left = 1920 TabIndex = 22 Top = 1920 Width = 495 End Begin VB.PictureBox picDisplay Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 255 Left = 120 ScaleHeight = 225 ScaleWidth = 2865 TabIndex = 19 Top = 120 Width = 2895 Begin VB.TextBox Text1 Alignment = 1 'Right Justify BorderStyle = 0 'None Height = 255 Left = 240 Locked = -1 'True TabIndex = 20 Top = 0 Width = 2535 End Begin VB.Label lblOperation Appearance = 0 'Flat BackColor = &H80000005& ForeColor = &H80000008& Height = 255 Left = 60 TabIndex = 21 Top = 0 Width = 255 End End Begin VB.CommandButton Command9 Caption = "退格" Height = 375 Left = 1920 TabIndex = 18 Top = 480 Width = 495 End Begin VB.CommandButton Command8 Caption = "清零" Height = 375 Left = 2520 TabIndex = 17 Top = 480 Width = 495 End Begin VB.CommandButton cmdDot Caption = "." Height = 375 Left = 120 TabIndex = 16 Top = 1920 Width = 495 End Begin VB.CommandButton Command7 Caption = "Sqrt" Height = 375 Left = 2520 TabIndex = 15 Top = 1920 Width = 495 End Begin VB.CommandButton Command6 Caption = "=" Height = 375 Left = 1320 TabIndex = 14 Top = 1920 Width = 495 End Begin VB.CommandButton Command5 Caption = "/" Height = 375 Left = 2520 TabIndex = 13 Top = 1440 Width = 495 End Begin VB.CommandButton Command4 Caption = "*" Height = 375 Left = 1920 TabIndex = 12 Top = 1440 Width = 495 End Begin VB.CommandButton Command3 Caption = "-" Height = 375 Left = 2520 TabIndex = 11 Top = 960 Width = 495 End Begin VB.CommandButton Command2 Caption = "+" Height = 375 Left = 1920 TabIndex = 10 Top = 960 Width = 495 End Begin VB.CommandButton Command1 Caption = "9" Height = 375 Index = 9 Left = 1320 TabIndex = 9 Top = 480 Width = 495 End Begin VB.CommandButton Command1 Caption = "8" Height = 375 Index = 8 Left = 720 TabIndex = 8 Top = 480 Width = 495 End Begin VB.CommandButton Command1 Caption = "7" Height = 375 Index = 7 Left = 120 TabIndex = 7 Top = 480 Width = 495 End Begin VB.CommandButton Command1 Caption = "6" Height = 375 Index = 6 Left = 1320 TabIndex = 6 Top = 960 Width = 495 End Begin VB.CommandButton Command1 Caption = "5" Height = 375 Index = 5 Left = 720 TabIndex = 5 Top = 960 Width = 495 End Begin VB.CommandButton Command1 Caption = "4" Height = 375 Index = 4 Left = 120 TabIndex = 4 Top = 960 Width = 495 End Begin VB.CommandButton Command1 Caption = "3" Height = 375 Index = 3 Left = 1320 TabIndex = 3 Top = 1440 Width = 495 End Begin VB.CommandButton Command1 Caption = "2" Height = 375 Index = 2 Left = 720 TabIndex = 2 Top = 1440 Width = 495 End Begin VB.CommandButton Command1 Caption = "1" Height = 375 Index = 1 Left = 120 TabIndex = 1 Top = 1440 Width = 495 End Begin VB.CommandButton Command1 Caption = "0" Height = 375 Index = 0 Left = 720 TabIndex = 0 Top = 1920 Width = 495 EndEndAttribute VB_Name = "frmmain"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalsePrivate Data As DoublePrivate lOperation As LongPrivate fClear As BooleanPrivate Sub cmdDot_Click()If InStr(1, Text1.Text, ".") <= 0 Then Text1.Text = Text1.Text & "."End SubPrivate Sub Command1_Click(Index As Integer)If fClear = True Then Text1.Text = "": fClear = FalseText1.Text = Text1.Text & IndexEnd SubPrivate Sub Command10_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)Case 5: Text1.Text = Data ^ Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 5lblOperation.Caption = "^"End SubPrivate Sub Command2_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)Case 5: Text1.Text = Data ^ Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 1lblOperation.Caption = "+"End SubPrivate Sub Command3_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)Case 5: Text1.Text = Data ^ Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 2lblOperation.Caption = "-"End SubPrivate Sub Command4_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)Case 5: Text1.Text = Data ^ Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 3lblOperation.Caption = "*"End SubPrivate Sub Command5_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)Case 5: Text1.Text = Data ^ Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 4lblOperation.Caption = "/"End SubPrivate Sub Command6_Click()If fClear = False ThenSelect Case lOperationCase 0Case 1: Text1.Text = Data + Val(Text1.Text)Case 2: Text1.Text = Data - Val(Text1.Text)Case 3: Text1.Text = Data * Val(Text1.Text)Case 4: If Val(Text1.Text) = 0 Then MsgBox "除数不等于0": Exit Sub Else Text1.Text = Data / Val(Text1.Text)Case 5: Text1.Text = Data ^ Val(Text1.Text)End SelectEnd IfData = Val(Text1.Text)fClear = TruelOperation = 0lblOperation.Caption = ""End SubPrivate Sub Command7_Click()If Val(Text1.Text) <= 0 Then MsgBox "开方数大于等于0"Text1.Text = Sqr(Val(Text1.Text))Data = Val(Text1.Text)fClear = TruelOperation = 0lblOperation.Caption = ""End SubPrivate Sub Command8_Click()Text1.Text = ""lOperation = 0lblOperation.Caption = ""End SubPrivate Sub Command9_Click()If Len(Text1.Text) > 0 Then Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1)End SubPrivate Sub Form_KeyPress(KeyAscii As Integer)Select Case KeyAsciiCase Asc("0"): Command1_Click 0Case Asc("1"): Command1_Click 1Case Asc("2"): Command1_Click 2Case Asc("3"): Command1_Click 3Case Asc("4"): Command1_Click 5Case Asc("5"): Command1_Click 4Case Asc("6"): Command1_Click 6Case Asc("7"): Command1_Click 7Case Asc("8"): Command1_Click 8Case Asc("9"): Command1_Click 9Case Asc("."): cmdDot_ClickCase Asc("+"): Command2_ClickCase Asc("-"): Command3_ClickCase Asc("*"): Command4_ClickCase Asc("/"): Command5_ClickCase Asc("^"): Command10_ClickCase Asc("s"): Command7_ClickCase Asc("S"): Command7_ClickCase vbKeyBack: Command9_ClickCase Asc("`"): Command8_ClickCase Asc("="): Command6_ClickCase 13: Command6_ClickEnd SelectKeyAscii = 0End Sub
如何用VB做一个简单计算器 要求实现加减乘除乘方开方功能 用0~9按钮实现 类似WINDOWS系统自带的计算器 最好带图
Windows自带的计算器,任何win系列系统都带有,请问科学型计算器里面统计功能的“s”按钮的公式是?
c语言计算器要求:1.能实现任意多个数之间的加减乘除乘方开方等运算.2.能实现记忆功能,即可保留最近十个结果,用#键查看
用java编写计算器 能够实现简单的加、减、乘、除、乘方、开方运算等;
用C语言编程,编一个简单的计算器,需要用什么函数?这个计算器的功能有加减乘除,还有乘方,要求小...
制作一个简单的计算器程序,实现加减乘除运算.
如何用windows内置的计算器实现二进制小数与十进制小数之间的转换?
求C++课设计算器,能实现加减乘除开方和带括号的按优先级运算.并将输入的一串运算式计算纪录保存至文档
用WINDOWS自带的计算器怎么算一个数的N次方啊
系统自带计算器中
用C编出一个科学计算器,至少同时实现五个数的+,-,*,/,简单的开方,平方等操作?
XP自带的科学型计算器开方运算?