首页 > 编程知识 正文

vb简单计算器编程代码,利用vb制作科学计算器

时间:2023-05-05 01:45:30 阅读:119568 作者:4878

科学计算机vb代码. doc

(第19页)。

此资源提供了全文预览。 点击全文预览可以进行全文预览。 如果你喜欢文档,请下载。 检索后会变得容易使用哦。

14.90个百分点

用VB写计算器的例子好像有很多,这个代码就是其中之一。 科学计算机是基本计算机加上角度、弧度、梯度、正切、馀切、余弦、平方根等数学计算而成。 当然,基础的加减乘除运算自不必说,这是一本VB教程中摘录的代码。 请以此为基础,充实扩展此计算器的功能,并尝试执行屏幕截图。 核心代码只有一个文件代码。 version 5.00 begin VB.form frm _ scientific caption='计算器' clientheight=2925 client left=165 client top=735 clientwidth form1' ale height=2925 scale width=5595 startup position=3'窗口中的默认begin VB.common on=' rnd ' height=390 left=5025 tabindex on cmd _ pi caption=' pi ' heig hhhh ndex=38 top=2400 width=630 endbeginvb.command button cmd _ fact caption=' n!' height=390 left=1575 tabindex=37 top=1935 width=630 endbeginvb.command button cmd _ log caption=' log ' height=390 lelelenve ncmd _ ln caption=' ln ' height=390 left=1575 tabindex=35 top=960 width=mandbuttoncmd _ square caption=' x ^2' heinde b.command button caption height=390 left=825 tabindex=33 top=1935 width=630 endbeginvb.command button cmd _ operator captior th=630 endbeginvb.command button cmd _ exp caption=' exp ' height=390 left=840 tabindex=31 top dbeginvb.commmand button cmand=30 top=960 width=630 endbeginvb.command bad=' cos ' height=390 left=120 tabindex=29 top=1455 width=630 endbeginvb . p=1935 width=630 endbeginvb.command button cmd _ atan caption=' atan ' height=390 left=120 tabindex=27 top=2440 gin VB . width=2625 begin VB.optionbuttonotn _ grd caption='坡度' height ab index=26 top=210 width=750 endbeginvb.optionbuttonon

25 Top = 210 Width = 795 End Begin VB.OptionButton Otn_Deg Caption = "角度" Height = 180 Left = 135 TabIndex = 24 Top = 210 Value = -1 'True Width = 675 End End Begin VB.CommandButton Cmd_Operator Caption = "=" Height = 390 Index = 4 Left = 5025 TabIndex = 22 Top = 2400 Width = 510 End Begin VB.CommandButton Cmd_Operator Caption = "+" Height = 390 Index = 3 Left = 4470 MaskColor = &H00808080& Style = 1 'Graphical TabIndex = 21 Top = 2400 Width = 510 End Begin VB.CommandButton Command1 Caption = "." Height = 390 Index = 11 Left = 3915 TabIndex = 20 Top = 2400 Width = 510 End Begin VB.CommandButton Command1 Caption = "+/-" Height = 390 Index = 10 Left = 3360 TabIndex = 19 Top = 2400 Width = 510 End Begin VB.CommandButton Command1 Caption = "0" Height = 390 Index = 0 Left = 2820 TabIndex = 18 Top = 2400 Width = 510 End Begin VB.CommandButton Cmd_fraction 。省略部分。t = "0." Then Exit Sub End If If (Txt_Result.Text "") Then Txt_Result.Text = Mid(Txt_Result.Text, 1, Len(Txt_Result.Text) - 1) ElseIf Txt_Result.Text = "" Then Txt_Result.Text = "0." End IfEnd SubPrivate Sub Cmd_C_Click() '清零 Txt_Result.Text = "0" prev = 0End SubPrivate Sub Cmd_CE_Click() dflag = 0 prev = 0 oflag = 0 ind = 0 opnre = 0 Txt_Result = " 0"End SubPrivate Sub Cmd_Cos_Click() 'Cos值 Txt_Result.Text = Str(Cos(ang * Val(Txt_Result.Text))) prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Cube_Click() Txt_Result.Text = Val(Txt_Result.Text) ^ 3 prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Exp_Click() '计算Exp的值 Txt_Result.Text = Exp(Txt_Result.Text) prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Fact_Click() 'N! Txt_Result.Text = Str(fac(Val(Txt_Result.Text))) prev = Txt_Result.TextEnd SubPrivate Sub Cmd_fraction_Click() '倒数 Dim Temp Temp = Val(Txt_Result.Text) If Temp 0 Then Txt_Result.Text = Str(1 / Temp) Else Txt_Result.Text = "除数不能为零。" End If prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Ln_Click() 'LN If Val(Txt_Result.Text) > 0 Then Txt_Result.Text = Str(Log(Val(Txt_Result.Text))) Else Txt_Result.Text = "输入有误。" End If prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Log_Click() 'Log If Val(Txt_Result.Text) > 0 Then Txt_Result.Text = Str((Log(Val(Txt_Result.Text)) / Log(10))) Else Txt_Result.Text = "输入有误。" End If prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Operator_Click(Index As Integer) ' 单击操作符按钮 If opnre = 0 Or Index = 4 Then If ind = 3 Then '加号 prev = prev + Val(Txt_Result.Text) ElseIf ind = 2 Then '减号 prev = prev - Val(Txt_Result.Text) ElseIf ind = 0 Then '除号 If Val(Txt_Result.Text) = 0 Then Txt_Result.Text = "除数不能为零。" Exit Sub Else prev = prev / Val(Txt_Result.Text) End If ElseIf ind = 5 Then 'X^Y prev = prev ^ Val(Txt_Result.Text) ElseIf ind = 1 Then '乘号 prev = prev * Val(Txt_Result.Text) End If If prev = 0 Then '如果前一个操作数为0 prev = Txt_Result.Text '将当前的值传给操作数 Else '否则 Txt_Result.Text = Str(prev) '将操作数的值传递给文本框显示 End If oflag = 0 End If opnre = 1 ind = Index dflag = 0End SubPrivate Sub Cmd_PI_Click() 'PI Txt_Result.Text = 3.141592654 prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Rnd_Click() '产生一个随机数 Txt_Result.Text = Str(Rnd)End SubPrivate Sub Cmd_Sin_Click() 'Sin值 Txt_Result.Text = Str(Sin(ang * Val(Txt_Result.Text))) prev = Txt_Result.TextEnd SubPrivate Sub Cmd_sqrt_Click() '求平方根 Dim Temp As Integer Temp = Val(Txt_Result.Text) If Temp > 0 Or Temp = 0 Then Txt_Result.Text = Str(Sqr(Val(Txt_Result.Text))) Else Txt_Result.Text = "函数输入无效。" End IfEnd SubPrivate Sub Cmd_Square_Click() '求平方 Txt_Result.Text = Val(Txt_Result.Text) ^ 2 prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Tan_Click() 'Tan函数 If (Cos(Val(Txt_Result.Text))) 0 Then Txt_Result.Text = Str(Sin(ang * Val(Txt_Result.Text)) / Cos(ang * Val(Txt_Result.Text))) Else Txt_Result.Text = "除数不能为零。" End If prev = Txt_Result.TextEnd SubPrivate Sub Command1_Click(Index As Integer) '数字键 If ind = 4 Then prev = 0 Txt_Result.Text = " " ind = 0 End If opnre = 0 If oflag = 0 Then Txt_Result.Text = " " End If oflag = 1 If Command1(Index).Caption "." Then If Txt_Result.Text "0." Then Txt_Result.Text = Txt_Result.Text & Command1(Index).Caption Else Txt_Result.Text = " " & Command1(Index).Caption End If Else If dflag = 0 Then Txt_Result.Text = Txt_Result.Text & "." dflag = 1 Else Txt_Result.Text = "输入有误。" End If End IfEnd SubPrivate Sub Form_Load() dflag = 0 prev = 0 oflag = 0 ind = 0 opnre = 0 Clipboard.ClearEnd SubPrivate Sub Menu_All_Click() '全选 Clipboard.Clear Clipboard.SetText Txt_Result.TextEnd SubPrivate Sub Menu_Copy_Click() '复制 Clipboard.Clear Clipboard.SetText Txt_Result.TextEnd SubPrivate Sub Menu_Cut_Click() '剪切 Clipboard.Clear Clipboard.SetText Txt_Result.Text Txt_Result.Text = ""End SubPrivate Sub Menu_Exit_Click() '退出 EndEnd SubPrivate Sub Menu_HelpSubject_Click() MsgBox "未开通帮助功能。", vbCriticalEnd SubPrivate Sub Menu_Paste_Click() '粘贴 Txt_Result.Text = "" Txt_Result.Text = Clipboard.GetText()End SubPrivate Sub Otn_Deg_Click() '角度 If Otn_Deg = True Then ang = 3.141592654 / 180 End IfEnd SubPrivate Sub Otn_Grd_Click() '梯度 If Otn_Grd.Value = True Then ang = 3.141592654 / 200 End IfEnd SubPrivate Sub Otn_Rad_Click() '弧度 If Otn_Rad.Value = True Then ang = 1 End IfEnd Sub'计算阶乘'**输 入:num(Long) - 要计算阶乘的数'**输 出:(Long) - 计算结果'**功能描述:计算一个小于12的数的阶乘Function fac(num As Long) As Long Dim re If (num 12) Then Txt_Result.Text = "输入的数值过大。" fac = num Else re = 1 While (num > 0) re = re * num num = num - 1 Wend fac = re End If End IfEnd FunctionVB科学计算器代码,新建一工程后引入上述代码文件编译即可。 关 键 词: 代码 计算器 科学 vb

 天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。