快捷登录,享 免费下载
首页 > 教程资讯 > 教程详情

VB代码计算器的教程

补充锦囊 完美下载小客服 2021-03-30
文章分享
软件首页

完美者(wmzhe.com)网站以软件下载为基础,改版后的网站对功能性板块进行扩充,以期能够解决用户在软件使用过程中遇见的所有问题。网站新增了“软件百科”、“锦囊妙技”等频道,可以更好地对用户的软件使用全周期进行更加专业地服务。

VB没有自带显示代码行数的功能,这个软件来弥补它的不足。操作非常简单,只需打开你编写的工程文件或直接拖动工程文件到窗口即可看到每个模块的行数和整个工程的总行数,还可以选择是否计算空行。本软件操作简单快捷,能自动识别VB工程主文件、VB工程文件、窗体文件、类模块文件等,并能在计算中自动减去由VB自动生成的代码,所以技术进度很高,能证实体现你的辛苦成果。它不仅能自动识别VB文件,其他只要是以文件形式存放在存储器上的都能计算。

"锦囊妙技"栏目是聚合全网软件使用的技巧或者软件使用过程中各种问题的解答类文章,栏目设立伊始,小编欢迎各路软件大神朋友们踊跃投稿,在完美者平台分享大家的独门技巧。

本站文章素材来源于网络,大部分文章作者名称佚失,为了更利于用户阅读和使用,根据需要进行了重新排版和部分改编,本站收录文章只是以帮助用户解决实际问题为目的,如有版权问题请联系小编修改或删除,谢谢合作。

VB代码计算器

VB代码计算器

软件大小:1.22 MB

高速下载

相关问答

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

    1、创建控件组的方法 首先创建一个命令按钮,调整其大小(觉得合适就行),名称为Command1,Caption 属性为数字 0 ;然后进行“复制”和“粘贴”,当选择“粘贴”时,出现对话框提示已有一个同名控件,询问是否创建控件组,选择“是”后,即创建了一个名为“Command”的控件组。 这时,第一个按钮的Index属性值默认为“0”,第二个的Index属性值自动设为“1”,并且大小与第一个按钮相同,只需修改其 Caption 属性为数字“1”并将其拖至合适位置即可。此后继续使用“粘贴”的方法建立其他控件组中其余按钮,共20个按钮,每建立一个,就将它拖到合适处,并修改相应的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编写计算器的代码

    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 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

  • 计算器的vb代码

    Dim a As Integer, b As Double, c As Double Private Sub Command1_Click(Index As Integer) Select Case Index Case 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 Text1.Text = Text1.Text & Index Case 10 If InStr(Text1.Text, ".") = flase Then Text1.Text = Text1.Text + "." End If Case 12, 13, 14, 15 c = Index b = Val(Text1.Text) Text1.Text = "" Case 11 If c = 12 Then Text1.Text = Str(Val(Text1.Text) + b) End If If c = 13 Then Text1.Text = Str(b - Val(Text1.Text)) End If If c = 14 Then Text1.Text = Str(Val(Text1.Text) * b) End If If c = 15 Then If Val(Text1.Text) = 0 Then MsgBox "分母不能为0", 64, "提示!" Text1.Text = "" Else Text1.Text = Str(b / Val(Text1.Text)) End If End If End Select End Sub Private Sub Command2_Click(Index As Integer) Select Case Index Case 0 Text1.Text = "" Case 1 Text1.Text = "" a = Len(Text1.Text) If Len(Text1.Text) > 1 Then Text1.Text = Left(Text1.Text, a - 1) End If Case 2 End Case 3 Text1.Text = "0" Text1.SetFocus End Select End Sub

  • 用vb编写计算器代码

    写一个计算器很烦的,你用100分估计才有人会帮你! 下面给你我写的FRM里的一部分代码,不能全发!其它还有10几个文件! 我的能实现金额大写,按键发声等等 不要问题要余下的代码了,不会回应的! Dim ClearDisplay As Boolean Dim Operand1 As Double Dim Operator As String, Browser As String Dim CmdStr As String Dim RetVal As Long Dim ErrStr As String * 256 '取数字变量 Dim mousePT As PointAPI Dim prevWindow As Long Dim Curwindow As Long Dim X As Long Dim Y As Long Dim TempStr As String Dim Subtemp As String Dim retValue As Long Dim parentWnd As Long Private Sub ClearB_Click() Display.Caption = "0" ClearDisplay = False Dim Ltp As Integer Ltp = GetSetting(App.EXEName, "Option", "Muse", 0) If Ltp = 1 Then Dowav (ClearB.Caption) End If Equals.SetFocus '等于获得焦点 End Sub Private Sub digits_Click(Index As Integer) If ClearDisplay = True Then Display.Caption = "" ClearDisplay = False End If If Display.Caption = "0" Then Display.Caption = digits(Index).Caption Display = CovertZ(Display) Else Display.Caption = Display.Caption + digits(Index).Caption Display = CovertZ(Display) End If '数字发音 Dim Ltp As Integer Ltp = GetSetting(App.EXEName, "Option", "Muse", 0) If Ltp = 1 Then Dowav (Converts(Trim(Str(Index)))) End If Equals.SetFocus '等于获得焦点 End Sub Private Sub Div_Click() If ClearDisplay = False And Operator <> "Num" Then Select Case Operator Case "+" Display = Operand1 + Val(Display) Case "-" Display = Operand1 - Val(Display) Case "*" Display = Operand1 * Val(Display) Case "/" If Display <> "0" Then Display = Operand1 / Val(Display) Else Display.Caption = "分母不能为零!" ClearDisplay = True Operand1 = 0 End If End Select Display = CovertZ(Display) End If Dim LtpX As Integer LtpX = GetSetting(App.EXEName, "Option", "Muse", 0) If LtpX = 1 Then Dim TempS As String Dim TempL As Integer Dim X As Integer Dim Ltp As Integer Ltp = GetSetting(App.EXEName, "Option", "Before", 0) If Ltp = 1 Then Dim Ltp1 As Integer Ltp1 = GetSetting(App.EXEName, "Option", "Currency", 0) If Ltp1 = 0 Then TempS = Up(CovertZX(Display)) Else TempS = Up1(CovertZX(Display)) End If If TempS = "元" Then TempS = "零元" End If TempL = Len(TempS) For X = 1 To TempL Dowav (Mid$(TempS, X, 1)) Next End If Dowav (Div.Caption) End If Operand1 = Val(Display.Caption) Operator = "/" ClearDisplay = True Equals.SetFocus '等于获得焦点 End Sub Private Sub Equals_Click() Dim Result As Double If ClearDisplay = False Then Select Case Operator Case "+" Result = Operand1 + Val(Display) Case "-" Result = Operand1 - Val(Display) Case "*" Result = Operand1 * Val(Display) Case "/" If Display <> "0" Then Result = Operand1 / Val(Display) Else Display.Caption = "分母不能为零!" ClearDisplay = True Operand1 = 0 End If Case Else Result = CovertZ(Display.Caption) End Select Display = CovertZ(Display) Else Result = Display.Caption Result = CovertZ(Display) End If ClearDisplay = True On Error GoTo ErrHand Display.Caption = CovertZ(CStr(Result)) Display.Refresh Dim LtpX As Integer LtpX = GetSetting(App.EXEName, "Option", "Muse", 0) If LtpX = 1 Then Dowav (Equals.Caption) Dim TempS As String Dim TempL As Integer Dim X As Integer Dim Ltp As Integer Ltp = GetSetting(App.EXEName, "Option", "Currency", 0) If Ltp = 0 Then TempS = Up(CovertZX(Display)) Else TempS = Up1(CovertZX(Display)) End If If TempS = "元" Then TempS = "零元" End If TempL = Len(TempS) For X = 1 To TempL Dowav (Mid$(TempS, X, 1)) Next End If '是否将结果发送剪贴板 Ltp = GetSetting(App.EXEName, "Option", "SetClip", 0) If Ltp = 1 Then Clipboard.SetText CStr(Result) End If Operand1 = 0 Operator = "Num" Exit Sub ErrHand: MsgBox "操作发生以下错误:" & Chr(10) & Chr(13) & Err.Description, vbOKOnly + vbCritical, "计算器出错" Display.Caption = "未知错误!" Operand1 = 0 Operator = "Num" ClearDisplay = True End Sub Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer) Select Case KeyCode Case 8 If Len(Display) > 1 Then Display = Left(Display, Len(Display) - 1) Display = CovertZ(Display) Else Display = "0" End If Case 13 Call Equals_Click Case 65 Call MnuHelp_Click Case 69 Call MnuExit_Click Case 79 Call MnuConfig_Click End Select End Sub