版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、· 用VB寫計(jì)算器似乎有很多例子,這個(gè)代碼就是其中之一,科學(xué)計(jì)算器是在基本計(jì)算器的基礎(chǔ)上,加入角度、弧度、梯度、正切、余切、正弦余弦、平方根等的數(shù)學(xué)計(jì)算,當(dāng)然基礎(chǔ)的加減乘除運(yùn)算就更不用說(shuō)了,這是在一本VB教程中摘錄的代碼,你可以此為基礎(chǔ)完善擴(kuò)展該計(jì)算器的功能,運(yùn)行截圖如下:核心代碼,只有一個(gè)文件代碼:VERSION 5.00Begin VB.Form Frm_Scientific Caption = "計(jì)算器" ClientHeight = 2925 ClientLeft = 165 ClientTop = 735 ClientWidth = 5595 LinkT
2、opic = "Form1" LockControls = -1 'True MaxButton = 0 'False ScaleHeight = 2925 ScaleWidth = 5595 StartUpPosition = 3 '窗口缺省 Begin VB.CommandButton Cmd_Rnd Caption = "Rnd" Height = 390 Left = 5025 TabIndex = 39 Top = 1455 Width = 510 End Begin VB.CommandButton Cmd_PI Ca
3、ption = "PI" Height = 390 Left = 1575 TabIndex = 38 Top = 2400 Width = 630 End Begin VB.CommandButton Cmd_Fact Caption = "N!" Height = 390 Left = 1575 TabIndex = 37 Top = 1935 Width = 630 End Begin VB.CommandButton Cmd_Log Caption = "Log" Height = 390 Left = 1575 TabInd
4、ex = 36 Top = 1455 Width = 630 End Begin VB.CommandButton Cmd_Ln Caption = "Ln" Height = 390 Left = 1575 TabIndex = 35 Top = 960 Width = 630 End Begin VB.CommandButton Cmd_Square Caption = "X2" Height = 390 Left = 840 TabIndex = 34 Top = 2400 Width = 630 End Begin VB.CommandButto
5、n Cmd_Cube Caption = "X3" Height = 390 Left = 825 TabIndex = 33 Top = 1935 Width = 630 End Begin VB.CommandButton Cmd_Operator Caption = "XY" Height = 390 Index = 5 Left = 840 TabIndex = 32 Top = 1455 Width = 630 End Begin VB.CommandButton Cmd_Exp Caption = "Exp" Height
6、 = 390 Left = 840 TabIndex = 31 Top = 960 Width = 630 End Begin VB.CommandButton Cmd_Sin Caption = "Sin" Height = 390 Left = 120 TabIndex = 30 Top = 960 Width = 630 End Begin VB.CommandButton Cmd_Cos Caption = "Cos" Height = 390 Left = 120 TabIndex = 29 Top = 1455 Width = 630 End
7、 Begin VB.CommandButton Cmd_Tan Caption = "Tan" Height = 390 Left = 120 TabIndex = 28 Top = 1935 Width = 630 End Begin VB.CommandButton Cmd_Atan Caption = "Atan" Height = 390 Left = 120 TabIndex = 27 Top = 2400 Width = 630 End Begin VB.Frame Frame1 Height = 510 Left = 90 TabIndex
8、 = 23 Top = 330 Width = 2625 Begin VB.OptionButton Otn_Grd Caption = "梯度" Height = 180 Left = 1695 TabIndex = 26 Top = 210 Width = 750 End Begin VB.OptionButton Otn_Rad Caption = "弧度" Height = 180 Left = 900 TabIndex = 25 Top = 210 Width = 795 End Begin VB.OptionButton Otn_Deg Ca
9、ption = "角度" 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 = "
10、+" 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 Com
11、mand1 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 Caption = "1/x&quo
12、t; Height = 390 Left = 5025 TabIndex = 17 Top = 1935 Width = 510 End Begin VB.CommandButton Cmd_sqrt Caption = "Sqrt" Height = 390 Left = 5025 TabIndex = 16 Top = 960 Width = 510 End Begin VB.CommandButton Cmd_C Caption = "C" Height = 405 Left = 4785 TabIndex = 15 Top = 405 Width
13、 = 750 End Begin VB.CommandButton Cmd_CE Caption = "CE" Height = 405 Left = 3975 TabIndex = 14 Top = 405 Width = 750 End Begin VB.CommandButton Cmd_Backspace Caption = "Backspace" Height = 405 Left = 2820 TabIndex = 13 Top = 405 Width = 1110 End Begin VB.CommandButton Cmd_Operato
14、r Caption = "-" Height = 390 Index = 2 Left = 4470 TabIndex = 12 Top = 1935 Width = 510 End Begin VB.CommandButton Cmd_Operator Caption = "*" Height = 390 Index = 1 Left = 4470 TabIndex = 11 Top = 1455 Width = 510 End Begin VB.CommandButton Cmd_Operator Caption = "/" He
15、ight = 390 Index = 0 Left = 4470 TabIndex = 10 Top = 960 Width = 510 End Begin VB.CommandButton Command1 Caption = "9" Height = 390 Index = 9 Left = 3915 TabIndex = 9 Top = 960 Width = 510 End Begin VB.CommandButton Command1 Caption = "8" Height = 390 Index = 8 Left = 3360 TabInd
16、ex = 8 Top = 960 Width = 510 End Begin VB.CommandButton Command1 Caption = "7" Height = 390 Index = 7 Left = 2820 TabIndex = 7 Top = 960 Width = 510 End Begin VB.CommandButton Command1 Caption = "6" Height = 390 Index = 6 Left = 3915 TabIndex = 6 Top = 1455 Width = 510 End Begin
17、VB.CommandButton Command1 Caption = "5" Height = 390 Index = 5 Left = 3360 TabIndex = 5 Top = 1455 Width = 510 End Begin VB.CommandButton Command1 Caption = "4" Height = 390 Index = 4 Left = 2820 TabIndex = 4 Top = 1455 Width = 510 End Begin VB.CommandButton Command1 Caption = &q
18、uot;3" Height = 390 Index = 3 Left = 3915 TabIndex = 3 Top = 1935 Width = 510 End Begin VB.CommandButton Command1 Caption = "2" Height = 390 Index = 2 Left = 3360 TabIndex = 2 Top = 1935 Width = 510 End Begin VB.CommandButton Command1 Caption = "1" Height = 390 Index = 1 Lef
19、t = 2820 TabIndex = 1 Top = 1935 Width = 510 End Begin VB.TextBox Txt_Result Alignment = 1 'Right Justify Height = 315 Left = 90 Locked = -1 'True TabIndex = 0 Text = "0." Top = 0 Width = 5385 End Begin VB.Menu Menu_Edit Caption = "編輯(&E)" Begin VB.Menu Menu_Copy Capt
20、ion = "復(fù)制" Shortcut = C End Begin VB.Menu Menu_Paste Caption = "粘貼" Shortcut = V End Begin VB.Menu Menu_Cut Caption = "剪切" Shortcut = X End Begin VB.Menu line1 Caption = "-" End Begin VB.Menu Menu_All Caption = "全選" Shortcut = A End Begin VB.Menu lin
21、e2 Caption = "-" End Begin VB.Menu Menu_Exit Caption = "退出" End End Begin VB.Menu Menu_Help Caption = "幫助(&H)" Begin VB.Menu Menu_HelpSubject Caption = "幫助主題(&H)" End Begin VB.Menu Menu_About Caption = "關(guān)于計(jì)算器" End EndEndAttribute VB_Name = &q
22、uot;Frm_Scientific"Attribute VB_GlobalNameSpace = FalseAttribute VB_Creatable = FalseAttribute VB_PredeclaredId = TrueAttribute VB_Exposed = FalseOption ExplicitDim que(25) As DoublePublic qt As IntegerPublic qh As IntegerPublic qv As IntegerPublic ang As DoublePublic memo As DoubleDim dflag As
23、 IntegerDim i As IntegerDim opnre As IntegerDim prev As DoubleDim oflag As IntegerDim ind As IntegerPrivate Sub Cmd_Atan_Click() 'Atan函數(shù) Txt_Result.Text = Str(Atn(Val(Txt_Result.Text) / ang) prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Backspace_Click() '退格 If Txt_Result.Text = "0."
24、; 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 =
25、 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.T
26、ext) 3 prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Exp_Click() '計(jì)算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() '倒數(shù) D
27、im Temp Temp = Val(Txt_Result.Text) If Temp <> 0 Then Txt_Result.Text = Str(1 / Temp) Else Txt_Result.Text = "除數(shù)不能為零。" 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_Re
28、sult.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_Cl
29、ick(Index As Integer) ' 單擊操作符按鈕 If opnre = 0 Or Index = 4 Then If ind = 3 Then '加號(hào) prev = prev + Val(Txt_Result.Text) ElseIf ind = 2 Then '減號(hào) prev = prev - Val(Txt_Result.Text) ElseIf ind = 0 Then '除號(hào) If Val(Txt_Result.Text) = 0 Then Txt_Result.Text = "除數(shù)不能為零。" Exit Sub Els
30、e prev = prev / Val(Txt_Result.Text) End If ElseIf ind = 5 Then 'XY prev = prev Val(Txt_Result.Text) ElseIf ind = 1 Then '乘號(hào) prev = prev * Val(Txt_Result.Text) End If If prev = 0 Then '如果前一個(gè)操作數(shù)為0 prev = Txt_Result.Text '將當(dāng)前的值傳給操作數(shù) Else '否則 Txt_Result.Text = Str(prev) '將操作數(shù)的值傳
31、遞給文本框顯示 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() '產(chǎn)生一個(gè)隨機(jī)數(shù) Txt_Result.Text = Str(Rnd)End SubPrivate Sub Cmd_Sin_Click() 'Sin值 Txt_Result.Text = Str(Si
32、n(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 = "函數(shù)輸入無(wú)效。" End IfEnd SubPrivate Sub Cmd_Squa
33、re_Click() '求平方 Txt_Result.Text = Val(Txt_Result.Text) 2 prev = Txt_Result.TextEnd SubPrivate Sub Cmd_Tan_Click() 'Tan函數(shù) 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 = "除數(shù)不能為零。&quo
34、t; End If prev = Txt_Result.TextEnd SubPrivate Sub Command1_Click(Index As Integer) '數(shù)字鍵 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
35、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.Text
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 網(wǎng)絡(luò)安全投標(biāo)售后保障
- 玩具店內(nèi)部裝修工裝施工合同
- 礦石材料標(biāo)簽規(guī)范
- 車站監(jiān)控系統(tǒng)施工合同
- 農(nóng)業(yè)用肥料標(biāo)簽管理辦法
- 鋁廠混凝土施工合同
- 咨詢公司財(cái)務(wù)規(guī)劃策略
- 環(huán)保技術(shù)開發(fā)招標(biāo)辦法
- 酒類批發(fā)市場(chǎng)衛(wèi)生條例
- 溫泉公園施工合同
- 2023年副主任醫(yī)師(副高)-神經(jīng)內(nèi)科學(xué)(副高)考試歷年真題薈萃帶答案
- 建筑施工安全檢查標(biāo)準(zhǔn)jgj592011圖解
- 鍋爐過(guò)熱蒸汽溫度控制系統(tǒng)課程設(shè)計(jì)
- 四川省成都市2021-2022學(xué)年高一(上)期末調(diào)研考試物理試題 Word版
- OFM軟件的一些使用技巧
- 國(guó)開電大《工程數(shù)學(xué)(本)》形成性考核作業(yè)5答案
- 《公司金融》模擬試題答案 東北財(cái)經(jīng)大學(xué)2023年春
- 2023-2024學(xué)年四川省樂(lè)山市小學(xué)數(shù)學(xué)四年級(jí)上冊(cè)期末??伎荚囶}
- 嚴(yán)蔚敏版數(shù)據(jù)結(jié)構(gòu)課后習(xí)題答案-完整版
- 工程進(jìn)度管理制度
- DL-T 870-2021 火力發(fā)電企業(yè)設(shè)備點(diǎn)檢定修管理導(dǎo)則
評(píng)論
0/150
提交評(píng)論