三九宝宝网宝宝百科宝宝知识

VB中加减计算器代码和圆代码

03月28日 编辑 39baobao.com

[c++实现计算器的方法和代码]中缀表达式转后缀表达式,考试大现在就用这个方式再实现计算器..表达式一旦转换成后缀表达式再进行计算就简单的不得了.Examda遇到一个符号就弹出离他最近的两个操作数然后...+阅读

先设置按钮“+”(Command1) “—”(Command2) 以及 text1 text2 text3 Private Sub Command1_Click() text3=str(text1)+ str(text2) END SUB Private Sub Command1_Click() text3=str(text1)- str(text2) END SUB 至于圆 dim paintnow as boolean dim curx as integer dim cury as integer Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) paintnow=true curx=x cury=y pset(x,y) End Sub

求VB中做计算器全代码

在窗体上放置以下控件:

1、lblResult Label控件 设置lblResult.Caption = 0

2、btnNum(0)~btnNum(9) 按钮控件数组,下标对应齐数字(如:btnNum(0).Caption=0,依次类推)

3、添加btnAdd(加法)、btnSub(减法)、btnMul(乘法)、btnDiv(除法)、btnEnter(等于号)、btnReset(清除键)六个按钮。 在窗体代码中输入以下内容: Dim byteOperation As Byte '操作符 Dim byteTmp As Byte '临时操作符 Dim intNum As Double '输入的数字 Sub Calc() Select Case byteOperation Case 1 'Add lblResult.Caption = CDbl(lblResult.Caption) + intNum Case 2 'Sub lblResult.Caption = intNum - CDbl(lblResult.Caption) Case 3 'Mul lblResult.Caption = CDbl(lblResult.Caption) * intNum Case 4 'Div lblResult.Caption = intNum / CDbl(lblResult.Caption) Case Else End Select End Sub Private Sub btnNum_Click(Index As Integer) If byteTmp0 Then intNum = lblResult.Caption lblResult.Caption = 0 byteTmp = 0 End If If lblResult.Caption = 0 Then lblResult.Caption = Index Else If Len(lblResult.Caption)

用VB编写一个计算器程序的代码

编辑一个有0~9、小数点、加减乘除的计算器 用一个窗体就可以实现,你可以试试 Option Explicit Dim strNumber As String Dim strPoint As String Dim dblNum1 As Double Dim intOperator As Integer '清除结果 Private Sub cmdGT_Click() txtDisplay.Text = "0." strNumber = "" strPoint = "." intOperator = 7 End Sub '输入数字 Private Sub cmdNumber_Click(Index As Integer) strNumber = strNumber & cmdNumber(Index).Caption txtDisplay.Text = strNumber & strPoint End Sub Private Sub cmdOnOff_Click() End End Sub '运算过程 Private Sub cmdOperator_Click(Index As Integer) Dim dblnum2 As Double '是第一次单击运算符时,将输入的值先赋给第一个数,否则赋值给第二个数进行运算 If intOperator = 7 Then dblNum1 = CDbl(txtDisplay.Text) Else dblnum2 = CDbl(Val(txtDisplay.Text)) '根据输入的符号进行运算 '求普通运算 Select Case intOperator Case 0 dblNum1 = dblNum1 + dblnum2 Case 1 dblNum1 = dblNum1 - dblnum2 Case 2 dblNum1 = dblNum1 * dblnum2 Case 3 If dblnum20 Then dblNum1 = dblNum1 / dblnum2 Else MsgBox "除数不能为“0”!请重新输入除数。", vbOKOnly + vbInformation, "除零错误" Index = intOperator End If Case 6 dblNum1 = dblNum1 * dblnum2 / 100 End Select End If '取得当前输入的运算符,以做下次运算 intOperator = Index strNumber = "" txtDisplay = CStr(dblNum1) '判断是否为文本框中的数字加点 If Not txtDisplay Like "*.*" Then txtDisplay.Text = txtDisplay.Text & "." End If End Sub Private Sub cmdOtherOper_Click(Index As Integer) Dim dblNum As Double '求平方根,平方, dblNum = CDbl(Val(txtDisplay.Text)) Select Case Index Case 0 '验证数据是否有效 If dblNum >= 0 Then txtDisplay.Text = CStr(Sqr(dblNum)) Else MsgBox "负数不能开平方根!", _ vbOKOnly + vbCritical, "开平方根错误" End If Case 1 txtDisplay.Text = CStr(dblNum ^ 2) End Select '判断是否为文本框中的数字加点 If Not txtDisplay Like "*.*" Then txtDisplay.Text = txtDisplay.Text & "." End If End Sub Private Sub cmdPoint_Click() strNumber = strNumber & strPoint strPoint = "" End Sub Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) '使被按下的数字键的对应按钮取得焦点 Select Case KeyCode Case 48 To 57 cmdNumber(KeyCode - 48).SetFocus Case 96 To 105 cmdNumber(KeyCode - 96).SetFocus Case Else '使按下的符号键对应的按钮取得焦点 If KeyCode = 107 Or (Shift = vbShiftMask And KeyCode = 187) Then cmdOperator(0).SetFocus cmdOperator_Click (0) ElseIf KeyCode = 109 Or KeyCode = 189 Then cmdOperator

(1).SetFocus cmdOperator_Click

(1) ElseIf KeyCode = 106 Or (Shift = vbShiftMask And KeyCode = 56) Then cmdOperator

(2).SetFocus cmdOperator_Click

(2) ElseIf KeyCode = 111 Or KeyCode = 191 Then cmdOperator

(3).SetFocus cmdOperator_Click

(3) ElseIf KeyCode = 13 Then cmdOperator

(7).SetFocus cmdOperator_Click

(7) ElseIf KeyCode = 8 Then cmdGT.SetFocus Call cmdGT_Click End If End Select End Sub Private Sub Form_KeyPress(KeyAscii As Integer) '将合法的数据输入到文本框 Select Case KeyAscii Case 48 To 58 '调用数字键点击处理程序 cmdNumber_Click KeyAscii - 48 KeyAscii = 0 Case 46 '调用小数点输入 cmdPoint_Click KeyAscii = 0 Case 13 '当敲击回车时,不能触发Form的 KeyUp 事件,因此在这里设置文本框的焦点 txtDisplay.SetFocus Case Else KeyAscii = 0 End Select End Sub Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer) txtDisplay.SetFocus End Sub Private Sub Form_Load() strNumber = "" strPoint = "." intOperator = 7 End Sub

VB计算器源代码!

Public Status, Status2 As Integer, tmp, tmp2, k As Single Private Sub Command1_Click(Index As Integer) If Text1 = "0" Then Text1 = "" Dim i, j As Integer Select Case Index Case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 If k = 0 And Status2 = 1 Then tmp = Text1 If k = 0 Then Text1 = "" k = k + 1 End If Text1.SetFocus SendKeys Index, True If Status = 0 Then tmp = Text1 If Status2 = 1 Then tmp2 = Text1 'PB by Jackiejor tmp; tmp2; Status; Status2; vbCrLf Case 10 For i = 1 To Len(Text1) If Mid(Text1, i, 1) = "." Then j = j + 1 Next i If j = 0 Then Text1.SetFocus SendKeys ".", True End If Case 11 'PB by Jackiejor tmp; tmp2; Status; Status2; vbCrLf Ans tmp = Text1 tmp2 = 0 SetStatus Status = 1 Status2 = 1 Case 12 'PB by Jackiejor tmp; tmp2; Status; Status2; vbCrLf Ans tmp = Text1 tmp2 = 0 SetStatus Status = 2 Status2 = 1 Case 13 'PB by Jackiejor tmp; tmp2; Status; Status2; vbCrLf Ans tmp = Text1 tmp2 = 1 SetStatus Status = 3 Status2 = 1 Case 14 'PB by Jackiejor tmp; tmp2; Status; Status2; vbCrLf Ans tmp = Text1 tmp2 = 1 SetStatus Status = 4 Status2 = 1 Case 15 If Status0 And Status2 = 0 Then tmp = Text1 'PB by Jackiejor tmp; tmp2; Status; Status2; vbCrLf Ans Text1 = Val(Text1) Status2 = 0 Case 16 Text1 = Val("") tmp = 0 tmp2 = 0 Status = 0 Status2 = 0 End Select End Sub Private Sub Form_Load() Dim i As Integer For i = 0 To 9 Command1(i).Caption = i Next i Text1 = Val(Text1) End Sub Private Sub SetStatus() Status = 0 k = 0 End Sub Private Sub Ans() Select Case Status Case 0 Exit Sub Case 1 Text1 = Val(tmp) + tmp2 Case 2 Text1 = Val(tmp) - tmp2 Case 3 Text1 = Val(tmp) * tmp2 Case 4 If Val(Text1) = 0 Then Exit Sub Text1 = Val(tmp) / tmp2 End Select End Sub

以下为关联文档:

计算机代码NOTES [1] 短语by far修饰比较级与级,强调数量、程度等,意为“……得多,最……”,这是一个用and 连接的并列句。 [2] to make sure是不定式短语作目的状语,其后的that引导的是mak...

判断是否闰年的vb代码1 2 3 4 5 6 7 8 9 10 11 12 Subs() y = Val(InputBox("请输入年份:")) Ify Mod4 Then GoTo100 ElseIf(y Mod100) = 0 Then Ify Mod400 ThenGoTo100 EndIf MsgBox y & "年是闰年!" Ex...

请教html计算器代码作为初学者,必须养成模块化思想和错误处理习惯。简单的代码写在下面。 _________ <html> <head> <title&gt;简单的计算器代码</title> </head> <body> <h1&gt;计算器</h1> 输入...

VB输入年份得到星期代码Private Sub Cmd1_Click()Dim c As IntegerDim y As Integer, m As Integer, d As IntegerDim w As Integerc = CInt(Text1.Text) \ 100y = CInt(Text1.Text) Mod 100m = CI...

VB程序代码时钟指针的相关代码求指教Const y0& = 1110, x0& = 1100, radius& = 750 【这一句看不懂】 'Const 是自定义常量的修饰符,Const y0& = 1110 等价于 Const y0 as long = 1110, &是long类型的简易表达 '...

vb中如何通过代码创建控件Option Explicit Private WithEvents NewButton As CommandButton '通过使用WithEvents关键字声明一个对象变量为新的命令按钮 Private Sub Command1_Click() If NewButton...

vb如何在代码中实现添加控件新建一个项目 在窗体上添加一个command1, 再添加一个command2, 将command2的index属性改为0. Dim i As Long Private Sub Command1_Click() Load Command2(i) With Command2(i...

excel vba代码中加入公式并填充公式软件版本:Office2007 方法如下: 1.利用VBA在C列中加入公式求AB列的和,并且填充公式至所有有数据的行: 2.Alt+F11,输入代码如下: 3.F5执行代码,返回Excel,得到结果如下:...

急!如何用VB代码创建一个名为代码创建数据库,表,字段Option ExplicitPrivate db As DatabasePrivate td As TableDefPrivate f As FieldPrivate Sub Command1_Click()Set db = DBEngine.CreateDatabase(...

推荐阅读
图文推荐