哪个高手帮忙做个用VB编程的计算器,给我代码,功能要高级点,谢谢
2007-06-13 13:17:05h***
哪个高手帮忙做个用VB编程的计算器,给我代码,功能要高级点,谢谢哪个高手帮忙做个用VB编程的计算器,给我代码,功能要高级点,谢谢:Option Explicit
Dim strNumber As String
Dim?
最佳回答
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 dblnum2 <> 0 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。
2007-06-13 13:20:16
很赞哦! (47)
相关文章
- VB高手帮帮忙题目做一个袖珍计算
- 用VB编写一个简单的计算器只要加
- 如何用VB代码写一个简单的计算器
- VB计算器编写程序RT,求VB计
- 想快速成为编程高手vb和delp
- 怎么编写一个学生信息管理系统?电
- 有没VB编程的高手,大作业,不会
- VB6.0操作数据库命令,高手帮
- 请VB高手帮下忙!谢谢我再做VB
- VB编程高手请进!请问:怎样用代
- 用VB编计算器,算法怎么写?像真
- VB遇到问题,希望高手帮忙解决,
- vb高手请进4、编程说明:在窗体
- 请教VB编程高手,请问这题该怎么
- 高手帮忙!VB浏览器的显示网页标
- 如何用vb做一个可以定时提醒的小
- (VB试题)用控件数组编写计算器
- VB编程高手进:有关系统错误提示
- 高分求计算器代码求VB或者VB.
- 计算器VB做的计算器啊!!谁有?
- 用VB编的窗体上有一个命令按钮和
- VB高手帮帮忙题目做一个袖珍计算
- 用VB编写一个简单的计算器只要加
- 如何用VB代码写一个简单的计算器
- VB计算器编写程序RT,求VB计
- 想快速成为编程高手vb和delp
- 怎么编写一个学生信息管理系统?电
- 有没VB编程的高手,大作业,不会
- VB6.0操作数据库命令,高手帮
- 请VB高手帮下忙!谢谢我再做VB
- VB编程高手请进!请问:怎样用代
- 用VB编计算器,算法怎么写?像真
- VB遇到问题,希望高手帮忙解决,
- vb高手请进4、编程说明:在窗体
- 请教VB编程高手,请问这题该怎么
- 高手帮忙!VB浏览器的显示网页标
- 如何用vb做一个可以定时提醒的小
- (VB试题)用控件数组编写计算器
- VB编程高手进:有关系统错误提示
- 高分求计算器代码求VB或者VB.
- 计算器VB做的计算器啊!!谁有?
- 用VB编的窗体上有一个命令按钮和