1.vb ������ Դ��
2.求有数字按键的计算b计简单vb计算器代码,谢谢
3.VB简易计算器代码怎么写
4.用VB做一个简单的器源加减乘除的计算器,代码是算器什么?
5.用vb设计一个计算器,里面的加减乘除按键的代码怎么写
6.用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 cmdDelete_Click()
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 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 cmdClearEntry_Click()
txtDisplay.Text = ""
End Sub
'清除显示内容,保存运算符
Private Sub cmdClear_Click()
cmdClearEntry_Click
StoredValue = 0
Operator = opNone
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 cmdPlusMinus_Click()
If NewEntry Then
txtDisplay.Text = "-"
ElseIf Left$(txtDisplay.Text, 1) = "-" Then
txtDisplay.Text = Right$(txtDisplay.Text, )
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
cmdDelete_Click
End Select
KeyCode = 0
End Sub
求有数字按键的简单vb计算器代码,谢谢
编写一个简单的计算b计VB计算器代码,需要定义一些变量和常量。器源东康his源码首先声明`StoredValue`为双精度数,算器`Operator`表示操作符,源码初始值设为`opNone`。计算b计在代码中,器源实现删除最后字符的算器功能,通过`cmdDelete_Click`事件处理。源码清除显示内容并保存操作符的计算b计vx授权app源码代码在`cmdClear_Click`中执行。
实现清除显示内容的器源逻辑在于`cmdClearEntry_Click`事件,将文本框`txtDisplay`的算器文本清空。在`cmdDecimal_Click`中处理小数点的显示,确保其在输入数字时不会重复出现。
`cmdEquals_Click`事件负责计算操作结果,根据`Operator`的值执行不同的数学操作,并更新`StoredValue`。同时,更新操作符、清除新输入标志,并将结果显示在文本框中。
在`cmdNumber_Click`和`cmdOperator_Click`中,韶关到深圳源码实现数字和操作符的输入。对于符号改变,使用`cmdPlusMinus_Click`事件处理正负号的切换。键盘输入处理通过`Form_KeyPress`和`Form_KeyUp`事件完成,确保各种按键输入都对应相应的功能。
文本框的焦点改变和输入改变事件分别由`txtDisplay_GotFocus`和`txtDisplay_Change`处理,确保在输入过程中文本框的正确行为。最后,使用`txtDisplay_KeyPress`和`txtDisplay_KeyUp`处理文本框的按键和释放事件,实现与用户的交互。
VB简易计算器代码怎么写
Dim a() As Double
Dim n&
Dim Plus As Boolean
Dim yunsuan() As Integer '------------这里增加
Dim a As Double
Private Sub cmd1_Click()
If Plus = True Then
Plus = False
Text1.Text = "1"
Else
Text1.Text = Text1.Text & "1"
End If
End Sub
Private Sub cmd2_Click()
If Plus = True Then
Plus = False
Text1.Text = "2"
Else
Text1.Text = Text1.Text & "2"
End If
End Sub
Private Sub cmd3_Click()
If Plus = True Then
Plus = False
Text1.Text = "3"
Else
Text1.Text = Text1.Text & "3"
End If
End Sub
Private Sub cmd4_Click()
If Plus = True Then
Plus = False
Text1.Text = "4"
Else
Text1.Text = Text1.Text & "4"
End If
End Sub
Private Sub cmd5_Click()
If Plus = True Then
Plus = False
Text1.Text = "5"
Else
Text1.Text = Text1.Text & "5"
End If
End Sub
Private Sub cmd6_Click()
If Plus = True Then
Plus = False
Text1.Text = "6"
Else
Text1.Text = Text1.Text & "6"
End If
End Sub
Private Sub cmd7_Click()
If Plus = True Then
Plus = False
Text1.Text = "7"
Else
Text1.Text = Text1.Text & "7"
End If
End Sub
Private Sub cmd8_Click()
If Plus = True Then
Plus = False
Text1.Text = "8"
Else
Text1.Text = Text1.Text & "8"
End If
End Sub
Private Sub cmd9_Click()
If Plus = True Then
Plus = False
Text1.Text = "9"
Else
Text1.Text = Text1.Text & "9"
End If
End Sub
Private Sub cmd0_Click()
If Plus = True Then
Plus = False
Text1.Text = "0"
Else
Text1.Text = Text1.Text & "0"
End If
End Sub
Private Sub cmdDian_Click()
If Plus = True Then
Plus = False
Text1.Text = "0."
Else
Text1.Text = Text1.Text & "."
End If
End Sub
Private Sub cmdjia_Click()
If Plus = False Then
a(n) = Val(Text1.Text)
yunsuan(n) = 0 '------这是在加号里
n = n + 1
Plus = True
End If
End Sub
Private Sub cmdjian_Click()
If Plus = False Then
a(n) = Val(Text1.Text)
yunsuan(n) = 1 '------这是在减号里
n = n + 1
Plus = True
End If
End Sub
Private Sub cmdcheng_Click()
If Plus = False Then
a(n) = Val(Text1.Text)
yunsuan(n) = 2 '------这是在乘号里
n = n + 1
Plus = True
End If
End Sub
Private Sub cmdchu_Click()
If Plus = False Then
a(n) = Val(Text1.Text)
yunsuan(n) = 3 '------这是在除号里
n = n + 1
Plus = True
End If
End Sub
Private Sub cmdDengyu_Click() '-------这是等于号
If Plus = False Then
a(n) = Val(Text1.Text)
End If
a() = a(0) '初始为a(0)
For i = 1 To
If yunsuan(i - 1) = 0 Then '------如果是加
a() = a() + a(i)
ElseIf yunsuan(i - 1) = 1 Then '----------如果是减
a() = a() - a(i)
ElseIf yunsuan(i - 1) = 2 Then '-----xxx
a() = a() * a(i)
ElseIf yunsuan(i - 1) = 3 Then '--------///
a() = a() / a(i)
End If
Next
Plus = False
Text1.Text = a()
n = 0
a = a()
Erase a
a(0) = a
Erase yunsuan '--------清理
End Sub
Private Sub Command_Click()
Text1.Text = ""
Erase a
Erase yunsuan
n = 0
End Sub
Private Sub Form_Load()
Text1.Locked = True
n = 0
Plus = False
End Sub
Private Sub form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = Then cmd1_Click
If KeyCode = Then cmd2_Click
If KeyCode = Then cmd3_Click
If KeyCode = Then cmd4_Click
If KeyCode = Then cmd5_Click
If KeyCode = Then cmd6_Click
If KeyCode = Then cmd7_Click
If KeyCode = Then cmd8_Click
If KeyCode = Then cmd9_Click
If KeyCode = Then cmd0_Click
If KeyCode = Then cmdDian_Click
If KeyCode = Then cmdjian_Click
If KeyCode = Then cmdDengyu_Click
If KeyCode = Then cmdchu_Click
If KeyCode = Then cmdjia_Click
If KeyCode = Then cmdcheng_Click
Debug.Print KeyCode, vbKey1
End Sub
用VB做一个简单的加减乘除的计算器,代码是溯源码操作视频什么?
我们现在首先要做的就是拉出Label,准备三个Label,把label1,label2,label3,这些改成第一个数、第二个数、结果。我们现在要text也要拉出三个,把了text里面text1、text2、text3全部删掉。
我们现在要把command拉出四个,python源码编译库把里面command1-4都给成+-*/
现在我们现在要双击+,我们开始进行输入代码
在里面我们现在要:text3.text=val(text1.text)+val(text2.text)
我们要把这个(text3.text=val(text1.text)+val(text2.text))复制,把里面+号分别改成-*/
如图,就像这样就可以了,可以行径了,如果你在哪个代码里弄错了,你看一下还要哪些没有拉出来,或者你哪个代码输错了。
感谢观看。
用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编写计算器的代码如何写
在窗体上放置以下控件,包括:
- 1个Label控件,命名为 lblResult,设置Caption为0。
- 数组按钮控件btnNum(0)~btnNum(9),下标对应数字(如:btnNum(0)的Caption设置为0,依次类推)。
- 六个按钮:btnAdd(加法)、btnSub(减法)、btnMul(乘法)、btnDiv(除法)、btnEnter(等于号)、btnReset(清除键)。
在窗体代码中输入以下内容:
定义变量:Dim byteOperation As Byte(操作符)、byteTmp As Byte(临时操作符)、intNum As Double(输入的数字)
Sub Calc()语句,根据byteOperation的值执行不同的计算操作,更新lblResult的Caption。
Sub btnNum_Click(Index As Integer)语句,接收输入按钮的数字,若byteTmp非0,则调用Calc()函数,设置byteOperation为1(加法)和byteTmp为1。
Sub btnReset_Click()语句,重置所有变量和lblResult的Caption为0。
Sub btnSub_Click()语句,若byteOperation非0,则调用Calc()函数,设置byteOperation为3(减法)和byteTmp为3。
Sub btnDiv_Click()语句,若byteOperation非0,则调用Calc()函数,设置byteOperation为4(除法)和byteTmp为4。
Sub btnEnter_Click()语句,调用Calc()函数,结束输入操作。
通过以上代码实现了一个基本的计算器功能,包括加、减、乘、除和清除功能。通过按钮点击触发相应操作,最终结果显示在lblResult控件中。
ç¨VBç¼åä¸ä¸ªè®¡ç®å¨ç¨åºç代ç
1ãå建æ§ä»¶ç»çæ¹æ³é¦å å建ä¸ä¸ªå½ä»¤æé®ï¼è°æ´å ¶å¤§å°ï¼è§å¾åéå°±è¡ï¼ï¼å称为Command1ï¼Caption å±æ§ä¸ºæ°å 0 ï¼ç¶åè¿è¡âå¤å¶âåâç²è´´âï¼å½éæ©âç²è´´âæ¶ï¼åºç°å¯¹è¯æ¡æ示已æä¸ä¸ªååæ§ä»¶ï¼è¯¢é®æ¯å¦å建æ§ä»¶ç»ï¼éæ©âæ¯âåï¼å³å建äºä¸ä¸ªå为âCommandâçæ§ä»¶ç»ã
è¿æ¶ï¼ç¬¬ä¸ä¸ªæé®çIndexå±æ§å¼é»è®¤ä¸ºâ0âï¼ç¬¬äºä¸ªçIndexå±æ§å¼èªå¨è®¾ä¸ºâ1âï¼å¹¶ä¸å¤§å°ä¸ç¬¬ä¸ä¸ªæé®ç¸åï¼åªéä¿®æ¹å ¶ Caption å±æ§ä¸ºæ°åâ1â并å°å ¶æè³åéä½ç½®å³å¯ãæ¤å继ç»ä½¿ç¨âç²è´´âçæ¹æ³å»ºç«å ¶ä»æ§ä»¶ç»ä¸å ¶ä½æé®ï¼å ±ä¸ªæé®ï¼æ¯å»ºç«ä¸ä¸ªï¼å°±å°å®æå°åéå¤ï¼å¹¶ä¿®æ¹ç¸åºçCaptionå±æ§å¼ã
2ãåæ§ä»¶ç»å ¶å±æ§è®¾ç½®å¦ä¸ï¼
设置ææå¦ä¸å¾æ示ï¼
äºãç¼å代ç
Dim s1 As Singleï¼ s2 As Singleï¼ ysf As String
âå®ä¹ä¸¤ä¸ªå精度æ°åéç¨ä¸åæ¾åä¸è¿ç®çæ°ï¼ä¸ä¸ªå符ååæ¾è¿ç®ç¬¦
Private Sub Command1_Clickï¼Index As Integerï¼
Text1.Text = Text1.Text & Command1ï¼Indexï¼.Caption âå°command1çåå»äºä»¶ä¸ææ¬æ¡æ¾ç¤ºçå 容è¿æ¥
End Sub
Private Sub Command2_Clickï¼ï¼
Text1.Text = Text1.Text + âãâ
If ï¼InStrï¼Text1.Textï¼ âãâï¼ = 1ï¼ Then â第ä¸ä½ä¸è½ä¸ºå°æ°
Text1.Text = ââ
End If
If InStrï¼Text1.Textï¼ âãâï¼ ã Lenï¼Text1.Textï¼ Then âé²æ¢åºç°ä¸¤ä¸ªå°æ°ç¹
Text1.Text = Left
ï¼Text1.Textï¼ Lenï¼Text1.Textï¼ - 1ï¼
End If
End Sub
Private Sub
Command3_Clickï¼ï¼
s2 = Valï¼Text1.Textï¼ âå¼å§å åä¹é¤è¿ç®
Select Case ysf Case â+â
Text1.Text = s1 + s2
Case â-â
Text1.Text = s1 - s2
Case â*â
Text1.Text = s1 * s2
Case â/â
If s2 = 0 Then
MsgBox âåæ¯ä¸è½ä¸ºé¶ï¼â
Text1.Text = ââ
Else
Text1.Text = s1 / s2 End If End Select
Text1 = IIfï¼Leftï¼Text1.Textï¼ 1ï¼ = âãâï¼ 0 & Text1.Textï¼ Text1.Textï¼ â
è¿ä¸ªå¾å ³é®ï¼å¦æ没æè¿ä¸ªçè¯ï¼å¾åºå°äº1çå°æ°åé¢æ²¡æ0
End Sub
Private Sub Command4_Clickï¼ï¼
If Text1.Text = ââ Then âææ¬ä¸ºç©ºå°±ç»æ
Exit Sub
End If
Text1.Text = Leftï¼Text1.Textï¼ Lenï¼Text1.Textï¼ - 1ï¼ âææ¬éä¸æ ¼
End Sub
Private Sub Command5_Clickï¼ï¼
Text1.Text = ââ âæ¸ é¤å½åæ¡å ææ¬
End Sub
Private Sub Command6_Clickï¼Index As Integerï¼
s1 = Valï¼Text1.Textï¼ âå°s1éèèµ·æ¥ ysf = Command6ï¼Indexï¼.Caption
Text1.Text = ââ
End Sub
Private Sub Command7_Clickï¼ï¼
If Leftï¼Text1.Textï¼ 1ï¼ ãã â-â Then âå¤æä½ä¸ºè´æ°
Text1.Text = â-â & Text1.Text
Else
Text1.Text = Rightï¼Text1.Textï¼ Lenï¼Text1.Textï¼ - 1ï¼
End If
End Sub
Private Sub Command8_Clickï¼ï¼
Text1.Text = Text1.Text * Text1.Text âå¹³æ¹
End Sub
æå±èµæVisual Basicï¼VBï¼æ¯ç±å¾®è½¯å ¬å¸å¼åçå å«ç¯å¢çäºä»¶é©±å¨ç¼ç¨è¯è¨ãå®æºèªäºBASICç¼ç¨è¯è¨ãVBæ¥æå¾å½¢ç¨æ·çé¢ï¼GUIï¼åå¿«éåºç¨ç¨åºå¼åï¼RADï¼ç³»ç»ï¼å¯ä»¥è½»æç使ç¨DAOãRDOãADOè¿æ¥æ°æ®åºï¼æè è½»æ¾çå建ActiveXæ§ä»¶ãç¨åºåå¯ä»¥è½»æ¾å°ä½¿ç¨VBæä¾çç»ä»¶å¿«éå建ä¸ä¸ªåºç¨ç¨åºã
åèé¾Visual Basicââç¾åº¦ç¾ç§æ¥
用VB设计出计算器的代码。。。但是不懂里面代码的意思 有没有大神解读一下啊 !!!没钱。。。大神啊。。
Private Sub Command1_Click()'按退格键,删除一个数字
Text1.Text = Left(Text1.Text, Len(Text1.Text) - 1) '退格
End Sub
Private Sub stand_Click()'修改计算器外型的大小为标准型
Form1.Width = '更改窗体尺寸
Form1.Height =
Text1.Width =
stand.Checked = True '标识标准型
science.Checked = False
End Sub
Private Sub Form_Load()‘启动时设置选择中标准型计算器
stand.Checked = True '默认标准型
End Sub