vb计算器加减乘除代码(用函数实现计算器加减乘除代码)

本篇文章给大家谈谈vb计算器加减乘除代码,以及用函数实现计算器加减乘除代码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

用vb编写一个计算器程序,实现加减乘除,

Dim v As Boolean

Dim s As Integer

Dim X As Double

Dim Y As Double

Private Sub Command1_Click(Index As Integer)

If Form1.Tag = "T" Then

If Index = 10 Then

Text1.Text = "0"

Else

Text1.Text = Command1(Index).Caption

End If

Form1.Tag = ""

Else

Text1.Text = Text1.Text Command1(Index).Caption

End If

End Sub

Private Sub Command2_Click(Index As Integer)

Form1.Tag = "T"

If v Then

X = Val(Text1.Text)

v = Not v

Else

Y = Val(Text1.Text)

Select Case s

Case 0

Text1.Text = X + Y

Case 1

Text1.Text = X - Y

Case 2

Text1.Text = X * Y

Case 3

If Y 0 Then

Text1.Text = X / Y

Else

MsgBox ("不能以0为除数")

Text1.Text = X

v = False

End If

Case 4

Y = 0

v = False

End Select

X = Val(Text1.Text)

End If

s = Index

End Sub

Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

控件自己添加吧,空间名要和代码名一致

用VB做一个简单的加减乘除的计算器,代码是什么?

我们现在首先要做的就是拉出Label,准备三个Label,把label1,label2,label3,这些改成第一个数、第二个数、结果。

我们现在要text也要拉出三个,把了text里面text1、text2、text3全部删掉。

我们现在要把command拉出四个,把里面command1-4都给成+-*/

现在我们现在要双击+,我们开始进行输入代码

在里面我们现在要:text3.text=val(text1.text)+val(text2.text)

我们要把这个(text3.text=val(text1.text)+val(text2.text))复制,把里面+号分别改成-*/

如图,就像这样就可以了,可以行径了,如果你在哪个代码里弄错了,你看一下还要哪些没有拉出来,或者你哪个代码输错了。

感谢观看。

如何用VB编写一个加减乘除计算器?只要代码!

Option Explicit

Dim Op1, Op2 Dim DecimalFlag As Integer Dim NumOps As Integer Dim LastInput

Dim OpFlag Dim TempReadout

Private Sub Cancel_Click()

Readout = Format(0, "0.")

Op1 = 0

Op2 = 0

Form_Load

End Sub

Private Sub CancelEntry_Click()

Readout = Format(0, "0.")

DecimalFlag = False

LastInput = "CE"

End Sub

Private Sub Decimal_Click()

If LastInput = "NEG" Then

Readout = Format(0, "-0.")

ElseIf LastInput "NUMS" Then

Readout = Format(0, "0.")

End If

DecimalFlag = True

LastInput = "NUMS"

End Sub

Private Sub Form_Load()

DecimalFlag = False

NumOps = 0

LastInput = "NONE"

OpFlag = " "

Readout = Format(0, "0.")

'Decimal.Caption = Format(0, ".")

End Sub

Private Sub Number_Click(Index As Integer)

If LastInput "NUMS" Then

Readout = Format(0, ".")

DecimalFlag = False

End If

If DecimalFlag Then

Readout = Readout + Number(Index).Caption

Else

Readout = Left(Readout, InStr(Readout, Format(0, ".")) - 1) + Number(Index).Caption + Format(0, ".")

End If

If LastInput = "NEG" Then Readout = "-" Readout

LastInput = "NUMS"

End Sub

Private Sub Operator_Click(Index As Integer)

TempReadout = Readout

If LastInput = "NUMS" Then

NumOps = NumOps + 1

End If

Select Case NumOps

Case 0

If Operator(Index).Caption = "-" And LastInput "NEG" Then

Readout = "-" Readout

LastInput = "NEG"

End If

Case 1

Op1 = Readout

If Operator(Index).Caption = "-" And LastInput "NUMS" And OpFlag "=" Then

Readout = "-"

LastInput = "NEG"

End If

Case 2

Op2 = TempReadout

Select Case OpFlag

Case "+"

Op1 = CDbl(Op1) + CDbl(Op2)

Case "-"

Op1 = CDbl(Op1) - CDbl(Op2)

Case "X"

Op1 = CDbl(Op1) * CDbl(Op2)

Case "/"

If Op2 = 0 Then

MsgBox "除数不能为 0", 48, "计算器"

Else

Op1 = CDbl(Op1) / CDbl(Op2)

End If

Case "="

Op1 = CDbl(Op2)

Case "%"

Op1 = CDbl(Op1) * CDbl(Op2)

End Select

Readout = Op1

NumOps = 1

End Select

If LastInput "NEG" Then

LastInput = "OPS"

OpFlag = Operator(Index).Caption

End If

End Sub

Private Sub Percent_Click()

Readout = Readout / 100

LastInput = "Ops"

OpFlag = "%"

NumOps = NumOps + 1

DecimalFlag = True

End Sub 窗体代码 VERSION 5.00

Begin VB.Form Calculator

BorderStyle = 1 'Fixed Single

Caption = "计算器"

ClientHeight = 2970

ClientLeft = 2580

ClientTop = 1485

ClientWidth = 3270

ClipControls = 0 'False

BeginProperty Font

Name = "System"

Size = 9.75

Charset = 0

Weight = 700

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

Icon = "CALC.frx":0000

LinkMode = 1 'Source

LinkTopic = "Form1"

MaxButton = 0 'False

PaletteMode = 1 'UseZOrder

ScaleHeight = 2970

ScaleWidth = 3270

WhatsThisHelp = -1 'True

Begin VB.CommandButton Number

Caption = "7"

Height = 480

Index = 7

Left = 120

TabIndex = 7

Top = 600

Width = 480

End

Begin VB.CommandButton Number

Caption = "8"

Height = 480

Index = 8

Left = 720

TabIndex = 8

Top = 600

Width = 480

End

Begin VB.CommandButton Number

Caption = "9"

Height = 480

Index = 9

Left = 1320

TabIndex = 9

Top = 600

Width = 480

End

Begin VB.CommandButton Cancel

Caption = "C"

Height = 480

Left = 2040

TabIndex = 10

Top = 600

Width = 480

End

Begin VB.CommandButton CancelEntry

Caption = "CE"

Height = 480

Left = 2640

TabIndex = 11

Top = 600

Width = 480

End

Begin VB.CommandButton Number

Caption = "4"

Height = 480

Index = 4

Left = 120

TabIndex = 4

Top = 1200

Width = 480

End

Begin VB.CommandButton Number

Caption = "5"

Height = 480

Index = 5

Left = 720

TabIndex = 5

Top = 1200

Width = 480

End

Begin VB.CommandButton Number

Caption = "6"

Height = 480

Index = 6

Left = 1320

TabIndex = 6

Top = 1200

Width = 480

End

Begin VB.CommandButton Operator

Caption = "+"

Height = 480

Index = 1

Left = 2040

TabIndex = 12

Top = 1200

Width = 480

End

Begin VB.CommandButton Operator

Caption = "-"

Height = 480

Index = 3

Left = 2640

TabIndex = 13

Top = 1200

Width = 480

End

Begin VB.CommandButton Number

Caption = "1"

Height = 480

Index = 1

Left = 120

TabIndex = 1

Top = 1800

Width = 480

End

Begin VB.CommandButton Number

Caption = "2"

Height = 480

Index = 2

Left = 720

TabIndex = 2

Top = 1800

Width = 480

End

Begin VB.CommandButton Number

Caption = "3"

Height = 480

Index = 3

Left = 1320

TabIndex = 3

Top = 1800

Width = 480

End

Begin VB.CommandButton Operator

Caption = "X"

Height = 480

Index = 2

Left = 2040

TabIndex = 14

Top = 1800

Width = 480

End

Begin VB.CommandButton Operator

Caption = "/"

Height = 480

Index = 0

Left = 2640

TabIndex = 15

Top = 1800

Width = 480

End

Begin VB.CommandButton Number

Caption = "0"

Height = 480

Index = 0

Left = 120

TabIndex = 0

Top = 2400

Width = 1080

End

Begin VB.CommandButton Decimal

Caption = "."

Height = 480

Left = 1320

TabIndex = 18

Top = 2400

Width = 480

End

Begin VB.CommandButton Operator

Caption = "="

Height = 480

Index = 4

Left = 2040

TabIndex = 16

Top = 2400

Width = 480

End

Begin VB.CommandButton Percent

Caption = "%"

Height = 480

Left = 2640

TabIndex = 17

Top = 2400

Width = 480

End

Begin VB.Label Readout

Alignment = 1 'Right Justify

BackColor = H0000FFFF

BorderStyle = 1 'Fixed Single

Caption = "0."

BeginProperty Font

Name = "MS Sans Serif"

Size = 12

Charset = 0

Weight = 700

Underline = 0 'False

Italic = 0 'False

Strikethrough = 0 'False

EndProperty

ForeColor = H00000000

Height = 375

Left = 120

TabIndex = 19

Top = 105

Width = 3000

End

End

Attribute VB_Name = "Calculator"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = False

Attribute VB_PredeclaredId = True

Attribute VB_Exposed = False

用vb设计一个计算器,里面的加减乘除按键的代码怎么写

简单点的:

dim 上一个数 as double

dim 下一个数 as double

dim 结果 as double

dim 操作 as string

private sub 加减乘除(byval sender as object, byval e as eventargs) handles 加.click, 减.click, 乘.click, 除.click

上一个数 = cdbl(输入框.text) ' 存储当前输入的数值

输入框.text = "" ' 等待下一个数值

select case sender.text ' 根据按下的按钮的文本属性确定你要做什么,这里可以用加减乘除号代替

case "加"

操作 = "加"

case "减"

操作 = "减"

case "乘"

操作 = "乘"

case "除"

操作 = "除"

end select

end sub

private sub 计算(byval sender as object, byval e as eventargs) handles 等号.click

下一个数 = 输入框.text

输入框.text = ”“

select case 操作

case "加"

结果 = 上一个数 + 下一个数

case "减"

结果 = 上一个数 - 下一个数

case "乘"

结果 = 上一个数 * 下一个数

case "除"

结果 = 上一个数 / 下一个数

end select

输入框.text = cstr(结果)

上一个数 = 结果

end sub

.NET 的哈,我没有 .NET 现在,不知道行不行

vb计算器加减乘除代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于用函数实现计算器加减乘除代码、vb计算器加减乘除代码的信息别忘了在本站进行查找喔。

1、本网站名称:源码村资源网
2、本站永久网址:https://www.yuanmacun.com
3、本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
源码村资源网 » vb计算器加减乘除代码(用函数实现计算器加减乘除代码)
您需要 登录账户 后才能发表评论

发表评论

欢迎 访客 发表评论