求有数字按键的简单vb计算器代码,插入到哪才能用呢

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 23:45:18

求有数字按键的简单vb计算器代码,插入到哪才能用呢
求有数字按键的简单vb计算器代码,
插入到哪才能用呢

求有数字按键的简单vb计算器代码,插入到哪才能用呢
Option Explicit
Private StoredValue As Double
Private Const opNone = 0
Private Const opAdd = 1
Private Const opSubtract = 2
Private Const opMultiply = 3
Private Const opDivide = 4
Private Operator As Integer
Private NewEntry As Boolean
'删除最后的字符
Private Sub DeleteCharacter()
Dim txt As String
Dim min_len As Integer
txt = txtDisplay.Text
If Left$(txt, 1) = "-" Then
min_len = 2
Else
min_len = 1
End If

If Len(txt) > min_len Then
txtDisplay.Text = Left$(txt, Len(txt) - 1)
Else
txtDisplay.Text = "0"
End If
End Sub
'清除显示内容,保存运算符
Private Sub cmdClear_Click()
cmdClearEntry_Click
StoredValue = 0
Operator = opNone
End Sub
'清除显示内容
Private Sub cmdClearEntry_Click()
txtDisplay.Text = ""
End Sub
' 显示小数点
Private Sub cmdDecimal_Click()
If InStr(txtDisplay.Text, ".") Then
Beep
Else
If NewEntry Then
txtDisplay.Text = "."
NewEntry = False
Else
txtDisplay.Text = txtDisplay.Text & "."
End If
End If
End Sub
'计算上一操作符的运算结果
Private Sub cmdEquals_Click()
Dim new_value As Double
If txtDisplay.Text = "" Then
new_value = 0
Else
new_value = CDbl(txtDisplay.Text)
End If
Select Case Operator
Case opNone
StoredValue = new_value
Case opAdd
StoredValue = StoredValue + new_value
Case opSubtract
StoredValue = StoredValue - new_value
Case opMultiply
StoredValue = StoredValue * new_value
Case opDivide
StoredValue = StoredValue / new_value
End Select
Operator = opNone
NewEntry = True
txtDisplay.Text = Format$(StoredValue)
End Sub
' 显示数字
Private Sub cmdNumber_Click(Index As Integer)
If NewEntry Then
txtDisplay.Text = Format$(Index)
NewEntry = False
Else
txtDisplay.Text = txtDisplay.Text & Format$(Index)
End If
End Sub
Private Sub cmdOperator_Click(Index As Integer)
cmdEquals_Click
Operator = Index
NewEntry = True
End Sub
'改变符号
Private Sub cmdPlusMinus_Click()
If NewEntry Then
txtDisplay.Text = "-"
ElseIf Left$(txtDisplay.Text, 1) = "-" Then
txtDisplay.Text = Right$(txtDisplay.Text, 2)
Else
txtDisplay.Text = "-" & txtDisplay.Text
End If
End Sub
'处理键盘按键
Private Sub Form_KeyPress(KeyAscii As Integer)
txtDisplay_KeyPress KeyAscii
End Sub
Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
txtDisplay_KeyUp KeyCode, Shift
End Sub
Private Sub txtDisplay_Change()
txtDisplay.SelStart = Len(txtDisplay.Text)
End Sub
Private Sub txtDisplay_GotFocus()
txtDisplay_Change
End Sub
Private Sub txtDisplay_KeyPress(KeyAscii As Integer)
Dim ch As String
ch = Chr$(KeyAscii)
Select Case ch
Case "0"
cmdNumber_Click 0
Case "1"
cmdNumber_Click 1
Case "2"
cmdNumber_Click 2
Case "3"
cmdNumber_Click 3
Case "4"
cmdNumber_Click 4
Case "5"
cmdNumber_Click 5
Case "6"
cmdNumber_Click 6
Case "7"
cmdNumber_Click 7
Case "8"
cmdNumber_Click 8
Case "9"
cmdNumber_Click 9
Case "*", "x", "X"
cmdOperator_Click opMultiply
Case "+"
cmdOperator_Click opAdd
Case vbCrLf, vbCr, "="
cmdEquals_Click
Case "-"
cmdOperator_Click opSubtract
Case "."
cmdDecimal_Click
Case "/"
cmdOperator_Click opDivide
Case "C", "c"
cmdClearEntry_Click
End Select
KeyAscii = 0
End Sub
Private Sub txtDisplay_KeyUp(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyNumpad0
cmdNumber_Click 0
Case vbKeyNumpad1
cmdNumber_Click 1
Case vbKeyNumpad2
cmdNumber_Click 2
Case vbKeyNumpad3
cmdNumber_Click 3
Case vbKeyNumpad4
cmdNumber_Click 4
Case vbKeyNumpad5
cmdNumber_Click 5
Case vbKeyNumpad6
cmdNumber_Click 6
Case vbKeyNumpad7
cmdNumber_Click 7
Case vbKeyNumpad8
cmdNumber_Click 8
Case vbKeyNumpad9
cmdNumber_Click 9
Case vbKeyMultiply
cmdOperator_Click opMultiply
Case vbKeyAdd
cmdOperator_Click opAdd
Case vbKeySeparator
cmdEquals_Click
Case vbKeySubtract
cmdOperator_Click opSubtract
Case vbKeyDecimal
cmdDecimal_Click
Case vbKeyDivide
cmdOperator_Click opDivide
Case vbKeyBack, vbKeyDelete
DeleteCharacter
End Select
KeyCode = 0
End Sub

求有数字按键的简单vb计算器代码,插入到哪才能用呢 计算器的数字和按键排列有什么规律? 计算器的数字和按键排列有什么规律 用VB编程设计一个类似于Windows附件中的计算器,如图所示,可进行简单的算术运算、三角函数和自然对数运算求代码,如果每条代码后面有说明就更好了,可以追加100 计算器数字键 清洗计算器按键黏黏的,怎么清洗到里面呢?有什么好又简单的方法呢? 如何用VB做一个简单计算器 要求实现加减乘除乘方开方功能 用0~9按钮实现 类似WINDOWS系统自带的计算器 最好带图最好有声明 代码太多 看着晃~ 求简单java写计算器代码加减乘除或者帮忙给个思路吧 恩 如何考虑编计算器呢我以前用VB编写过简单计算器 有什么同理吗都得怎么长吗 能给出个思路吗 卡西欧5800p计算器clac按键出来的简单字母代数公式,怎么存储到程序公式里面去 VB排列 数字的那个,打印PRINT的那个,循环的那个~求代码, 找一个计算器,仔细观察,把主要的键填出来,说说数字和按键的排列有什么规律 在VB中计算器的代码(要求0到9的加减乘除运算)只要0到9的加减乘除还有等于号其他都不需要 易语言程序计算器数字按钮代码怎么写我是易语言的初学者,我想做个简单的计算器.加、减、乘、除、的代码我已经摸索出来了,但数字键的代码不懂, 计算器上数字和按键排列规律 计算器上的C 按键 和 CE 按键 有什么区别? 请指导 求一vb程序代码,输入三个数字判断是等腰三角形,等边三角形,一般三角形还是不是三角形.只要是输出结果有4个的vb代码都可以!不要判断直角,锐角,钝角三角形的 有没有笔算正切公式,我想用VB 做个简单的计算器,输入值就可以知道角度了. 怎么在VB中求和我是想编一个简单计算器,编到求和这块不太会了,下面是我写的代码,麻烦帮我想一下Sub op()T1.Enabled = TrueT1.Visible = TrueT1.SetFocusEnd SubSub oi()T1.Enabled = FalseT1.Visible = FalseEnd SubPrivate 我有一个vb程序,目的是:把一个给定数插到有序数列中,插入后数列仍然有序.我编写的插不进去数,谁能帮我看看,代码在下边,我的vb学得很烂,期待着你们能帮我看一下Private Sub Instert(a(),x As Sin