怎样做一个简单的VB计算器
答案:1 悬赏:0 手机版
解决时间 2021-05-18 14:17
- 提问者网友:嘚啵嘚啵
- 2021-05-17 16:47
我刚学VB想做一个简单的计算器、就是不知道该怎样确定两个变量的值!另外想求一个师父能帮我…
最佳答案
- 五星知识达人网友:神也偏爱
- 2021-05-17 17:28
Dim min_len As Integer txt = txtDisplay.Text If Left$(txt, 1) = "-" Then min_len = 2 Else min_len = 1 End If If Len(txt) > min_len Then txtDisplay.Text = Left$(txt, Len(txt) - 1) Else txtDisplay.Text = "0" End IfEnd Sub ' Clear the current entry.Private Sub cmdClearEntry_Click() txtDisplay.Text = ""End Sub' Add a decimal point to the display.Private Sub cmdDecimal_Click() If InStr(txtDisplay.Text, ".") Then Beep Else If NewEntry Then txtDisplay.Text = "." NewEntry = False Else txtDisplay.Text = txtDisplay.Text & "." End If End IfEnd Sub ' Calculate the result of the previous operation.Private Sub cmdEquals_Click()Dim new_value As Double If txtDisplay.Text = "" Then new_value = 0 Else new_value = CDbl(txtDisplay.Text) End If Select Case Operator Case opNone StoredValue = new_value Case opAdd StoredValue = StoredValue + new_value Case opSubtract StoredValue = StoredValue - new_value Case opMultiply StoredValue = StoredValue * new_value Case opDivide StoredValue = StoredValue / new_value End Select Operator = opNone NewEntry = True txtDisplay.Text = Format$(StoredValue)End Sub ' Add a number to the display.Private Sub cmdNumber_Click(Index As Integer) If NewEntry Then txtDisplay.Text = Format$(Index) NewEntry = False Else txtDisplay.Text = _ txtDisplay.Text & Format$(Index) End IfEnd Sub ' Prepare to perform an operation.Private Sub cmdOperator_Click(Index As Integer) ' Perform the previous operation. cmdEquals_Click ' Remember this operation. Operator = Index ' Start a new value. NewEntry = TrueEnd Sub ' Change the value's sign.Private Sub cmdPlusMinus_
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯