当前位置:首页 > 代码 > 正文

简易计算器vb代码(简易计算器vb代码是什么)

admin 发布:2022-12-19 06:01 90


本篇文章给大家谈谈简易计算器vb代码,以及简易计算器vb代码是什么对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

VB简单计算器代码

Public choice As String

Public current As Double

Public prev As Double

Public counter As Integer

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub ac_Click()

Text1.Text = ""

prev = current = 0

'dz.Visible = False

'asterisk.Enabled = False

'equal.Enabled = False

'expo.Enabled = False

'logn.Enabled = False

'logten.Enabled = False

'minus.Enabled = False

'plus.Enabled = False

'sign.Enabled = False

'slash.Enabled = False

'sroot.Enabled = False

'cosine.Enabled = False

'sine.Enabled = False

'tangent.Enabled = False

'invsine.Visible = False

'invcos.Visible = False

'invtan.Visible = False

'expo.Visible = False

End Sub

Private Sub asterisk_Click()

Text1.Text = ""

choice = "*"

prev = current

current = 0

End Sub

Private Sub Command1_Click(Index As Integer)

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

current = Text1.Text

asterisk.Enabled = True

equal.Enabled = True

expo.Enabled = True

' logn.Enabled = True

' logten.Enabled = True

minus.Enabled = True

plus.Enabled = True

sign.Enabled = True

slash.Enabled = True

sroot.Enabled = True

' tangent.Enabled = True

'' cosine.Enabled = True

' sine.Enabled = True

End Sub

Private Sub Command3_Click()

Dim MyAngle, MyHSin

MyAngle = 1.3 ' 定义角度(以"弧度"为单位)

MsgBox (Exp(MyAngle) - Exp(-1 * MyAngle)) / 2 ' 计算双曲正弦函数值(sin())

End Sub

Private Sub cosine_Click()

Text1.Text = Cos(current * 3.14159265358979 / 180)

current = Cos(current * 3.14159265358979 / 180)

End Sub

Private Sub equal_Click()

On Error GoTo MyErr

If choice = "+" Then

current = prev + current

Text1.Text = current

ElseIf choice = "-" Then

current = prev - current

Text1.Text = current

ElseIf choice = "*" Then

current = prev * current

Text1.Text = current

ElseIf choice = "/" And current 0 Then

current = prev / current

Text1.Text = current

Else

Text1.Text = "Press AC to continue"

dz.Visible = True

dz.Caption = "Division by ZERO"

End If

If current 0 Then

sroot.Enabled = False

Else

sroot.Enabled = True

End If

Exit Sub

MyErr:

MsgBox Err.Description, vbInformation, "信息提示"

End Sub

Private Sub expo_Click()

On Error GoTo MyErr

Exit Sub

MyErr:

MsgBox Err.Description, vbInformation, "信息提示"

End Sub

Private Sub expo10_Click()

Dim i As Integer

Dim j As Double

j = current

current = 1

For i = 1 To j Step 1

current = current * 10

Next i

Text1.Text = current

End Sub

Private Sub Form_Unload(Cancel As Integer)

Dim value As Integer

End Sub

Private Sub invcos_Click()

Dim temp As Double

temp = current * 3.14159265358979 / 180

If (temp = 1 And temp = -1) Then

Text1.Text = 1 / Cos(temp)

current = 1 / Cos(temp)

End If

invsine.Visible = False

invcos.Visible = False

invtan.Visible = False

expo.Visible = False

expo10.Visible = False

End Sub

Private Sub invsine_Click()

Dim temp As Double

temp = current * 3.14159265358979 / 180

If (temp = 1 And temp = -1) Then

Text1.Text = 1 / Sin(temp)

current = 1 / Sin(temp)

End If

End Sub

Private Sub invtan_Click()

Text1.Text = 1 / Tan(current * 3.14159265358979 / 180)

current = 1 / Tan(current * 3.14159265358979 / 180)

invsine.Visible = False

invcos.Visible = False

invtan.Visible = False

expo.Visible = False

expo10.Visible = False

End Sub

Private Sub logn_Click()

Text1.Text = Log(current)

current = Log(current)

End Sub

Private Sub logten_Click()

Text1.Text = Log(current) / Log(10)

current = Log(current) / Log(10)

End Sub

Private Sub mode_MouseDown(Button As Integer, shift As Integer, X As Single, Y As Single)

counter = counter + 1

If counter 2 Then

counter = 1

End If

If counter = 2 Then

displaylb.Caption = "Normal Calculator"

displaylb.ForeColor = HFFC0C0

Form1.Width = 4830

sine.Visible = False

cosine.Visible = False

tangent.Visible = False

logn.Visible = False

logten.Visible = False

random.Enabled = False

random.Visible = False

shiftb.Visible = False

recall.Visible = False

Else

displaylb.Caption = " Scientific Calculator"

displaylb.ForeColor = HC0

Form1.Width = 5670

sine.Visible = True

cosine.Visible = True

tangent.Visible = True

logn.Visible = True

logten.Visible = True

random.Enabled = True

random.Visible = True

shiftb.Visible = True

recall.Visible = True

End If

End Sub

Private Sub point_Click()

If Text1.Text = "" Then

Text1.Text = "0."

Else

Text1.Text = Text1.Text "."

End If

End Sub

Private Sub random_Click()

Text1.Text = (2.1021020134 * Rnd + 1)

End Sub

Private Sub recall_Click()

Text1.Text = current

End Sub

Private Sub shiftb_Click()

invsine.Visible = True

invcos.Visible = True

invtan.Visible = True

expo.Visible = True

expo10.Visible = True

If Text1.Text = 1 And Text1.Text = -1 Then

invsine.Enabled = True

invcos.Enabled = True

End If

invtan.Enabled = True

expo.Enabled = True

expo10.Enabled = True

End Sub

Private Sub sign_Click()

If current 0 Then

Text1.Text = -current

current = -current

Else

Text1.Text = "-" Text1.Text

current = -current

End If

If current 0 Then

sroot.Enabled = False

Else

sroot.Enabled = True

End If

End Sub

Private Sub minus_Click()

Text1.Text = ""

choice = "-"

prev = current

current = 0

End Sub

Private Sub plus_Click()

Text1.Text = ""

choice = "+"

prev = current

current = 0

End Sub

Private Sub sine_Click()

Text1.Text = Sin(current * 3.14159265358979 / 180)

current = Sin(current * 3.14159265358979 / 180)

End Sub

Private Sub slash_Click()

Text1.Text = ""

choice = "/"

prev = current

current = 0

End Sub

Private Sub sroot_Click()

On Error GoTo MyErr

Text1.Text = Sqr(current)

current = Sqr(current)

Exit Sub

MyErr:

MsgBox Err.Description, vbInformation, "信息提示"

End Sub

Private Sub tangent_Click()

Text1.Text = Tan(current * 3.14159265358979 / 180)

current = Tan(current * 3.14159265358979 / 180)

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计算器简易代码,要容易看懂的

说明:1.共有4个文本框其,其中三个是填入或输出数据的(名称分别是:txta txtb txtc),剩下的那个是符号(txtd)2.共7个按钮,4个是符号按钮,一个计算,一个清零.这是我弄的程序”袖珍计算器”代码如下:通用声明Dim j As Integer '定义j为整型

Private Sub Text1_Change()End SubPrivate Sub Command1_Click()

txtfuhao.Text = "+" '将”+”显示到文本框txtfuhao.Text中

End SubPrivate Sub Command2_Click()

txtfuhao.Text = "-" ''将”-”显示到文本框txtfuhao.Text中

End SubPrivate Sub Command3_Click()

txtfuhao.Text = "×" '将”×”显示到文本框txtfuhao.Text中

End SubPrivate Sub Command4_Click()

txtfuhao.Text = "÷" 将”÷”'显示到文本框txtfuhao.Text中

End Sub

Private Sub Command5_Click()

Dim a, b, c As Integer

a = Val(txta.Text) '将txta.Text里的内容转化为数值型,然后再赋给a

b = Val(txtb.Text) '将txtb.Text里的内容转化为数值型,然后再赋给b

If txtfuhao.Text = "+" Then '运算过程

c = a + b '运算过程

ElseIf txtfuhao.Text = "-" Then '运算过程

c = a - b '运算过程

ElseIf txtfuhao.Text = "÷" Then '运算过程

c = a / b '运算过程

ElseIf txtfuhao.Text = "×" Then '运算过程

c = a * b '运算过程

Else

j = MsgBox("您输入的符号不正确", vbOKOnly, "错误信息")

End If

txtc.Text = c '将运算结果c输出到文本框txtc中

End SubPrivate Sub Command6_Click()

txta.Text = "" '将空字符输入到文本框内(刷新)

txtb.Text = "" '将空字符输入到文本框内(刷新)

txtc.Text = "" '将空字符输入到文本框内(刷新)

txtfuhao.Text = "" '将空字符输入到文本框内(刷新)

End SubPrivate Sub Command7_Click()

End '结束程序

End SubPrivate Sub Form_Load()End Sub

简易计算器vb代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于简易计算器vb代码是什么、简易计算器vb代码的信息别忘了在本站进行查找喔。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/3496.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载