我是新學VB的,想自己試著編一個文本框的計算器,哪位兄弟能幫忙看下,這點代碼問題出在哪里了,不勝感激。
Private Sub cmddsignchange_Click() '添加正負號
Dim data As Integer
data = Val(Txtscreen.Text)
length = Len(Txtscreen.Text)
If data > 0 Then
Txtscreen.Text = data * (-1)
Else
Txtscreen.Text = Right(Txtscreen.Text, length - 1)
End If
End Sub
Private Sub cmdequ_Click() '等號
Dim result As Double
Dim second As Double
second = Val(Txtscreen.Text)
sign = Index
Select Case sign
Case 0
result = first + second
Case 1
result = first - second
Case 2
result = first * second
Case 3
If second = 0 Then
MsgBox "除數不能為零"
Else
result = first / second
End If
End Select
Txtscreen.Text = CStr(result)
End Sub
Private Sub cmdnumber_Click(Index As Integer)
If Txtscreen.Text = "0" Then
Txtscreen.Text = CStr(Index)
Else
Txtscreen.Text = Txtscreen.Text & CStr(Index)
End If
End Sub
Private Sub Cmdon_Click()
Txtscreen.Text = "0"
End Sub
Private Sub cmdoperater_Click(Index As Integer)
Dim first As Double
first = Val(Txtscreen.Text)
Txtscreen.Text = "0"
End Sub
Private Sub cmdpoint_Click()
Txtscreen.Text = Txtscreen.Text & "."
End Sub
Private Sub Form_Load()
For Index = 0 To 9
cmdnumber(Index).Caption = cmdnumber(Index).Index
Next Index
End Sub
uj5u.com熱心網友回復:
http://download.csdn.net/download/stu_fly/4149067http://download.csdn.net/detail/joeyu2009/1742268
http://download.csdn.net/detail/asd155655153/3421259
http://download.csdn.net/download/abcemituofo/833793
http://download.csdn.net/download/tony19810929/933182
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/110960.html
標籤:VB基礎類
