原始碼:down.gogobox.com.tw/t2329175/ocuo2
Public Class Form1
Dim Flag, MathFlag As Integer
Dim DotNum, Num, SDotNum, SNum, Ans, MR As Double
Dim Dot As Boolean = False
Dim Newx As Boolean = True
Dim tmp1, tmp2, tmp
Private Function FixEx(ByVal x As Double) As Double
tmp = ""
If x < 0 Then tmp = "-"
x = Math.Abs(x)
tmp1 = Fix(x)
x = x - tmp1
While Fix(x) <> x
x *= 10
End While
If tmp = "-" Then x *= -1
Return x
End Function
Enum MathX
Add = 1
Subtract = 2
Multiply = 3
divide = 4
End Enum
Enum Number
HEX = 1
TEN = 2
OCT = 3
Binary = 4
End Enum
Private Sub CH13()
Newx = False
Select Case Flag
Case Number.OCT
While Math.Abs(SDotNum) >= 1
SDotNum /= 10
End While
While Math.Abs(DotNum) >= 1
DotNum /= 10
End While
tmp1 = SNum + SDotNum
tmp2 = Num + DotNum
Select Case MathFlag
Case MathX.Add
Ans = tmp1 + tmp2
SNum = Fix(Ans)
SDotNum = FixEx(Ans)
Case MathX.Subtract
Ans = tmp1 - tmp2
SNum = Fix(Ans)
SDotNum = FixEx(Ans)
Case MathX.Multiply
Ans = tmp1 * tmp2
SNum = Fix(Ans)
SDotNum = FixEx(Ans)
Case MathX.divide
Ans = tmp1 / tmp2
SNum = Fix(Ans)
SDotNum = FixEx(Ans)
End Select
End Select
End Sub
Private Sub ShowNow()
Select Case Flag
Case Number.OCT
If Num = 0 And DotNum = 0 Then
CountBox.Text = "0."
ElseIf DotNum = 0 Then
CountBox.Text = Str(Num) & "."
Else
CountBox.Text = Str(Num) & "." & Str(DotNum)
End If
End Select
If Ans <> 0 Then
If Fix(Ans) = 0 And FixEx(Ans) = 0 Then
CountBox.Text = "0."
ElseIf FixEx(Ans) = 0 Then
CountBox.Text = Str(Fix(Ans)) & "."
Else
If Ans < 1 Then
CountBox.Text = "0" & Str(Ans)
Else
CountBox.Text = Str(Ans)
End If
End If
End If
CountBox.Text = Replace(CountBox.Text, " ", "")
End Sub
Private Sub MathGo()
If SNum = 0 And SDotNum = 0 Then
save()
Zero()
Else
CH13()
Num = 0
DotNum = 0
End If
End Sub
Private Sub save()
SNum = Num
SDotNum = DotNum
End Sub
Private Sub Zero()
Ans = 0
Num = 0
DotNum = 0
Dot = False
End Sub
Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress
Select Case Flag
Case Number.OCT
Select Case e.KeyChar
Case "."
Dot = True
Case Chr(8)
Ans = 0
If Dot = True And DotNum = 0 Then
Dot = False
ElseIf Dot = True Then
DotNum /= 10
DotNum = Fix(DotNum)
ElseIf Num > 0 Then
Num /= 10
Num = Fix(Num)
End If
Case "+"
MathGo()
MathFlag = MathX.Add
Case "-"
MathGo()
MathFlag = MathX.Subtract
Case "*"
MathGo()
MathFlag = MathX.Multiply
Case "/"
MathGo()
MathFlag = MathX.divide
Case Chr(13)
CH13()
Case "0" To "9"
Ans = 0
If Newx = False Then
Newx = True
Zero()
save()
End If
If Dot = False Then
If Num = 0 Then
Num = Val(e.KeyChar)
Else
Num = Num * 10 + Val(e.KeyChar)
End If
Else
If DotNum = 0 Then
DotNum = Val(e.KeyChar)
Else
DotNum = DotNum * 10 + Val(e.KeyChar)
End If
End If
End Select
End Select
ShowNow()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CountBox.Text = "0."
Flag = Number.OCT
DB.Checked = True
MathFlag = 0
End Sub
Private Sub BCC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BCC.Click
SNum = 0
SDotNum = 0
Num = 0
DotNum = 0
Dot = False
Ans = 0
Newx = True
ShowNow()
GOGOBOX.Focus()
End Sub
Private Sub B0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B0.Click
SendKeys.Send("{0}")
End Sub
Private Sub B1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B1.Click
SendKeys.Send("{1}")
End Sub
Private Sub B2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B2.Click
SendKeys.Send("{2}")
End Sub
Private Sub B3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B3.Click
SendKeys.Send("{3}")
End Sub
Private Sub B4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B4.Click
SendKeys.Send("{4}")
End Sub
Private Sub B5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B5.Click
SendKeys.Send("{5}")
End Sub
Private Sub B6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B6.Click
SendKeys.Send("{6}")
End Sub
Private Sub B7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B7.Click
SendKeys.Send("{7}")
End Sub
Private Sub B8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B8.Click
SendKeys.Send("{8}")
End Sub
Private Sub B9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles B9.Click
SendKeys.Send("{9}")
End Sub
Private Sub Badd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Badd.Click
SendKeys.Send("{+}")
End Sub
Private Sub Bsub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bsub.Click
SendKeys.Send("{-}")
End Sub
Private Sub Bmul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bmul.Click
SendKeys.Send("{*}")
End Sub
Private Sub Bdiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bdiv.Click
SendKeys.Send("{/}")
End Sub
Private Sub Beq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Beq.Click
CH13()
ShowNow()
End Sub
Private Sub Bx2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bx2.Click
While DotNum > 0
DotNum /= 10
End While
tmp = Num + DotNum
Ans = tmp ^ 2
Num = Fix(Ans)
DotNum = FixEx(Ans)
ShowNow()
End Sub
Private Sub Bx3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bx3.Click
While DotNum > 0
DotNum /= 10
End While
tmp = Num + DotNum
Ans = tmp ^ 3
Num = Fix(Ans)
DotNum = FixEx(Ans)
ShowNow()
End Sub
Private Sub BMS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BMS.Click
While DotNum > 0
DotNum /= 10
End While
tmp = Num + DotNum
MR = tmp
End Sub
Private Sub BMR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BMR.Click
Zero()
save()
Ans = MR
ShowNow()
End Sub
Private Sub BMM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BMM.Click
While DotNum > 0
DotNum /= 10
End While
tmp = Num + DotNum
MR += tmp
End Sub
Private Sub BMC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BMC.Click
MR = 0
End Sub
Private Sub Bpi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bpi.Click
Zero()
Num = 3
DotNum = 4 * Math.Atan(1) - 3
ShowNow()
End Sub
Private Sub GOGOBOX_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GOGOBOX.Click
CH13()
ShowNow()
End Sub
Private Sub BInt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BInt.Click
Ans = 0
DotNum = 0
ShowNow()
End Sub
Private Sub 關於小算盤ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 關於小算盤ToolStripMenuItem.Click
MsgBox("真的非常抱歉,缺少的功能實在很多。", MsgBoxStyle.OkOnly, "關於")
End Sub
Private Sub 說明主題ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 說明主題ToolStripMenuItem.Click
MsgBox("真的非常抱歉,只有基本的功能。", MsgBoxStyle.OkOnly, "說明主題")
End Sub
End Class
全站熱搜