vb.net高手請進,這個小算盤程式寫的還行嗎?


vb.net高手請進,這個小算盤程式寫的還行嗎?
vb.net高手請進,這個小算盤程式寫的還行嗎?
vb.net高手請進,這個小算盤程式寫的還行嗎?
vb.net高手請進,這個小算盤程式寫的還行嗎?
vb.net高手請進,這個小算盤程式寫的還行嗎?
vb.net高手請進,這個小算盤程式寫的還行嗎?

若文字看不清楚,可參考下列程式碼

Public Class Form1
Dim firstnum As Decimal
Dim a As String

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
TextBox1.SelectionStart = TextBox1.TextLength
End Sub

Private Sub b0_Click(sender As System.Object, e As System.EventArgs) Handles b0.Click
onezero(0)
End Sub

Private Sub b1_Click(sender As System.Object, e As System.EventArgs) Handles b1.Click
onezero(1)
End Sub

Private Sub b2_Click(sender As System.Object, e As System.EventArgs) Handles b2.Click
onezero(2)
End Sub

Private Sub b3_Click(sender As System.Object, e As System.EventArgs) Handles b3.Click
onezero(3)
End Sub

Private Sub b4_Click(sender As System.Object, e As System.EventArgs) Handles b4.Click
onezero(4)
End Sub

Private Sub b5_Click(sender As System.Object, e As System.EventArgs) Handles b5.Click
onezero(5)
End Sub

Private Sub b6_Click(sender As System.Object, e As System.EventArgs) Handles b6.Click
onezero(6)
End Sub

Private Sub b7_Click(sender As System.Object, e As System.EventArgs) Handles b7.Click
onezero(7)
End Sub

Private Sub b8_Click(sender As System.Object, e As System.EventArgs) Handles b8.Click
onezero(8)
End Sub

Private Sub b9_Click(sender As System.Object, e As System.EventArgs) Handles b9.Click
onezero(9)
End Sub

Private Sub onezero(ByVal number As Integer)
If TextBox1.Text.Length < 19 Then<br>If TextBox1.Text = "0" Then
TextBox1.Text = number
Else
TextBox1.Text &= number
End If
End If
textbox1focus()
End Sub

Private Sub Bdelete_Click(sender As System.Object, e As System.EventArgs) Handles Bdelete.Click
TextBox1.Text = 0
textbox1focus()
End Sub

Private Sub bbackspace_Click(sender As System.Object, e As System.EventArgs) Handles bbackspace.Click
If TextBox1.Text.Length > 1 Then
TextBox1.Text = TextBox1.Text.Remove(TextBox1.Text.Length - 1, 1)
ElseIf TextBox1.Text.Length = 1 Then
TextBox1.Text = 0
End If
textbox1focus()
End Sub

Private Sub bpoint_Click(sender As System.Object, e As System.EventArgs) Handles bpoint.Click
If TextBox1.Text.Contains(".") Then
Else
TextBox1.Text &= "."
End If
textbox1focus()
End Sub

Private Sub bequal_Click(sender As System.Object, e As System.EventArgs) Handles bequal.Click
equal()
textbox1focus()
End Sub

Private Sub baddition_Click(sender As System.Object, e As System.EventArgs) Handles baddition.Click
operatorname("+")
End Sub

Private Sub bsubtraction_Click(sender As System.Object, e As System.EventArgs) Handles bsubtraction.Click
operatorname("-")
End Sub

Private Sub bmultiplication_Click(sender As System.Object, e As System.EventArgs) Handles bmultiplication.Click
operatorname("*")
End Sub

Private Sub bdivision_Click(sender As System.Object, e As System.EventArgs) Handles bdivision.Click
operatorname("/")
End Sub

Private Sub operatorname(ByVal oname As String)
firstnum = TextBox1.Text
TextBox1.Text = 0
a = oname
textbox1focus()
End Sub

Private Sub bor_Click(sender As System.Object, e As System.EventArgs) Handles bor.Click
If TextBox1.Text.Contains("-") Then
TextBox1.Text = TextBox1.Text.Remove(0, 1)
Else
TextBox1.Text = "-" & TextBox1.Text
End If
textbox1focus()
End Sub

Private Sub bpercent_Click(sender As System.Object, e As System.EventArgs) Handles bpercent.Click
TextBox1.Text = firstnum * TextBox1.Text / 100
textbox1focus()
End Sub

Private Sub TextBox1_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If (Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57) And (Asc(e.KeyChar) 8) Then
e.Handled = True
Select Case Asc(e.KeyChar)
Case 46
If TextBox1.Text.Contains(".") Then
Else
TextBox1.Text &= "."
End If
Case 43
operatorname("+")
Case 45
operatorname("-")
Case 42
operatorname("*")
Case 47
operatorname("/")
Case 61
equal()
Case 13
equal()
End Select
Else
If TextBox1.Text = "0" Then
TextBox1.Text = ""
End If
End If
textbox1focus()
End Sub
Private Sub textbox1focus()
TextBox1.Focus()
TextBox1.SelectionStart = TextBox1.TextLength
End Sub
Private Sub equal()
If a = "" Then
Else
Select Case a
Case "+"
TextBox1.Text = firstnum + TextBox1.Text
Case "-"
TextBox1.Text = firstnum - TextBox1.Text
Case "*"
TextBox1.Text = firstnum * TextBox1.Text
Case "/"
TextBox1.Text = firstnum / TextBox1.Text
End Select
a = ""
End If
End Sub
End Class
2016-04-17 19:18 發佈
所有的bx_click可以全部或是分類別整合成一個,按照keypress來反應.
還離商品化有點距離,請加油,建議參考類似程式.
感覺不知目的為和
abollar wrote:
若文字看不清楚,可...(恕刪)
很不錯的程式,以後可以再多多分享,彼此多多揣摩
內文搜尋
X
評分
評分
複製連結
Mobile01提醒您
您目前瀏覽的是行動版網頁
是否切換到電腦版網頁呢?