【vb精品源码栏目提醒】:网学会员在vb精品源码频道为大家收集整理了“计算器vb源代码 - 编程语言“提供大家参考,希望对大家有所帮助!
计算器
vb 源代码.txt 如果中了一千万,我就去买 30 套房子租给别人,每天都去收一次房租。
哇咔咔充实骑白马的不一定是王子,可能是唐僧;带翅膀的也不一定是天使,有时候是鸟人。
完全版的前后台代码...请把下面的保存为 form1.frm VERSION 5.00 Begin
VB.Form Calculator BorderStyle 1 Fixed Single Caption quot计算器quot ClientHeight 2970 ClientLeft 2580 ClientTop 1485 ClientWidth 3270 ClipControls 0 False BeginProperty Font Name quotSystemquot Size 9.75 Charset 0 Weight 700 Underline 0 False Italic 0 False Strikethrough 0 False EndProperty Icon quotCALC.frxquot:0000 LinkMode 1 Source LinkTopic quotForm1quot MaxButton 0 False PaletteMode 1 UseZOrder ScaleHeight 2970 ScaleWidth 3270 WhatsThisHelp -1 True Begin
VB.CommandButton Number Caption quot7quot Height 480 Index 7 Left 120 TabIndex 7 Top 600 Width 480 End Begin
VB.CommandButton Number Caption quot8quot Height 480 Index 8 Left 720 TabIndex 8 Top 600 Width 480EndBegin
VB.CommandButton Number Caption quot9quot Height 480 Index 9 Left 1320 TabIndex 9 Top 600 Width 480EndBegin
VB.CommandButton Cancel Caption quotCquot Height 480 Left 2040 TabIndex 10 Top 600 Width 480EndBegin
VB.CommandButton CancelEntry Caption quotCEquot Height 480 Left 2640 TabIndex 11 Top 600 Width 480EndBegin
VB.CommandButton Number Caption quot4quot Height 480 Index 4 Left 120 TabIndex 4 Top 1200 Width 480EndBegin
VB.CommandButton Number Caption quot5quot Height 480 Index 5 Left 720 TabIndex 5 Top 1200 Width 480EndBegin
VB.CommandButton Number Caption quot6quot Height 480 Index 6 Left 1320 TabIndex 6 Top 1200 Width 480EndBegin
VB.CommandButton Operator Caption quotquot Height 480 Index 1 Left 2040 TabIndex 12 Top 1200 Width 480EndBegin
VB.CommandButton Operator Caption quot-quot Height 480 Index 3 Left 2640 TabIndex 13 Top 1200 Width 480EndBegin
VB.CommandButton Number Caption quot1quot Height 480 Index 1 Left 120 TabIndex 1 Top 1800 Width 480EndBegin
VB.CommandButton Number Caption quot2quot Height 480 Index 2 Left 720 TabIndex 2 Top 1800 Width 480EndBegin
VB.CommandButton Number Caption quot3quot Height 480 Index 3 Left 1320 TabIndex 3 Top 1800 Width 480EndBegin
VB.CommandButton Operator Caption quotXquot Height 480 Index 2 Left 2040 TabIndex 14 Top 1800 Width 480EndBegin
VB.CommandButton Operator Caption quot/quot Height 480 Index 0 Left 2640 TabIndex 15 Top 1800 Width 480EndBegin
VB.CommandButton Number Caption quot0quot Height 480 Index 0 Left 120 TabIndex 0 Top 2400 Width 1080EndBegin
VB.CommandButton Decimal Caption quot.quot Height 480 Left 1320 TabIndex 18 Top 2400 Width 480EndBegin
VB.CommandButton Operator Caption quotquot Height 480 Index 4 Left 2040 TabIndex 16 Top 2400 Width 480EndBegin
VB.CommandButton Percent Caption quotquot Height 480 Left 2640 TabIndex 17 Top 2400 Width 480EndBegin
VB.Label Readout Alignment 1 Right Justify BackColor ampH0000FFFFamp BorderStyle 1 Fixed Single Caption quot0.quot BeginProperty Font Name quotMS Sans Serifquot Size 12 Charset 0 Weight 700 Underline 0 False Italic 0 False Strikethrough 0 False EndProperty ForeColor ampH00000000amp Height 375 Left 120 TabIndex 19 Top 105 Width 3000EndEndAttribute
VB_Name quotCalculatorquotAttribute
VB_GlobalNameSpace FalseAttribute
VB_Creatable FalseAttribute
VB_PredeclaredId TrueAttribute
VB_Exposed False -------------------------------------------------------------------------- 版权所有 C 1994 Microsoft Corporation 您可以免费以任何方式使用、修改、复制并分发您认为有用的 示例应用程序文件 或任何修改过的版本。
Microsoft 对任何 示例应用程序文件不做任何保证,不负任何责任和义务。
--------------------------------------------------------------------------Option ExplicitDim Op1 Op2 前面输入的操作数Dim DecimalFlag As Integer 小数点仍然存在吗?Dim NumOps As Integer 操作数个数Dim LastInput 指示上一次按键事件的类型Dim OpFlag 指示未完成的操作Dim TempReadout C 取消 按钮的 Click 事件过程 重新设置显示并初始化变量Private Sub Cancel_Click Readout Format0 quot0.quot Op1 0 Op2 0 Form_LoadEnd Sub CE 取消输入 按钮的 Click 事件过程Private Sub CancelEntry_Click Readout Format0 quot0.quot DecimalFlag False LastInput quotCEquotEnd Sub 小数点 . 按钮的 Click 事件过程 如果上一次按键为运算符,初始化 readout 为 quot0.quot; 否则显示时追加一个小数点Private Sub Decimal_Click If LastInput quotNEGquot Then Readout Format0 quot-0.quot ElseIf LastInput ltgt quotNUMSquot Then Readout Format0 quot0.quot End If DecimalFlag True LastInput quotNUMSquot End Sub 窗体的初始化过程 设置所有变量为其初始值 Private Sub Form_Load DecimalFlag False NumOps 0 LastInput quotNONEquot OpFlag quot quot Readout Format0 quot0.quot Decimal.Caption Format0 quot.quot End Sub 数字键 0-9 的 Click 事件过程 向显示中的数追加新数 Private Sub Number_ClickIndex As Integer If LastInput ltgt quotNUMSquot Then Readout Format0 quot.quot DecimalFlag False End If If DecimalFlag Then Readout Readout NumberIndex.Caption Else Readout LeftReadout InStrReadout Format0quot.quot - 1 NumberIndex.Caption Format0 quot.quot End If If LastInput quotNEGquot Then Readout quot-quot amp Readout LastInput quotNUMSquot End Sub 运算符 - x / 的 Click 事件过程 如果接下来的按键是数字键,增加 NumOps。
如果有一个操作数,则设置 Op1。
如果有两个操作数,则将 Op1 设置为 Op1 与 当前输入字符串的运算结果,并显示结果 Private Sub Operator_ClickIndex As Integer TempReadout Readout If LastInput quotNUMSquot Then NumOps NumOps 1 End If Select Case NumOps Case 0 If OperatorIndex.Caption quot-quot And LastInput ltgtquotNEGquot Then Readout quot-quot amp Readout LastInput quotNEGquot End If Case 1 Op1 Readout If OperatorIndex.Caption quot-quot And LastInput ltgtquotNUMSquot And OpFlag ltgt quotquot Then Readout quot-quot LastInput quotNEGquot End If Case 2 Op2 TempReadout Select Case OpFlag Case quotquot Op1 CDblOp1 CDblOp2 Case quot-quot Op1 CDblOp1 - CDblOp2 Case quotXquot Op1 CDblOp1 CDblOp2 Case quot/quot If Op2 0 Then MsgBox quot除数不能为 0quot 48 quot计算器quot Else Op1 CDblOp1 / CDblOp2 End If Case quotquot Op1 CDblOp2 Case quotquot Op1 CDblOp1 CDblOp2 End Select Readout Op1 NumOps 1 End Select If LastInput ltgt quotNEGquot Then LastInput quotOPSquot OpFlag OperatorIndex.Caption End If End Sub 百分比键 的 Click 事件过程 计算并显示第一个操作数的百分数Private Sub Percent_Click Readout Readout .