当前位置:编程学习 > VB >>

vb运行错误 :实时错误 13 类型不匹配


那位大哥帮忙看看

Private storedvalue As Double
Private Const opnone = 0
Private Const opadd = 1
Private Const opsubtract = 2  '减
Private Const opmultiply = 3  '乘
Private Const opdivide = 4   '除
Private operator As Integer
Private newentry As Boolean

Private Sub cmdclear_Click()
cmdclearentry_Click
storedvalue = 0
operator = opnone
End Sub

Private Sub cmdclearentry_Click()
txtdisplay.Text = ""
End Sub

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 If
End Sub

Private Sub cmdequals_Click()
Dim new_value As Double
If txtdisplay.Text = "" Then
new_value = 0
Else
new_value = (txtdisplay.Text) '这里错误 实时错误 13 类型不匹配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

Private Sub cmdNumber_Click(Index As Integer)
If newentry Then
txtdisplay.Text = Format$(Index) '强制返回值
newentry = False
Else
txtdisplay.Text = txtdisplay.Text & Format$(Index)
End If
End Sub

Private Sub cmdoperator_Click(Index As Integer)
cmdequals_Click
operator = Index
newentry = True
End Sub

Private Sub cmdplusminus_Click()
If newentry Then
txtdisplay.Text = "-"
ElseIf Left$(txtdisplay.Text, 1) = "-" Then
txtdisplay.Text = Right$(txtdisplay.Text, Len(txtdisplay.Text) - 1)
Else
txtdisplay.Text = "-" & txtdisplay.Text
End If
End Sub

Private Sub Command1_Click()
Dim txt As String
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 If
End Sub

Private Sub Command2_Click()
txt = Sqr(Val(txtdisplay.Text))
txtdisplay.Text = txt
End Sub

Private Sub Command3_Click()
txtdisplay.Text = txtdisplay.Text * 100 & "%"
End Sub

Private Sub Command4_Click()
txtdisplay.Text = 1 / Val(txtdisplay.Text)
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
txtdisplay_KeyPress KeyAscii
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
txtdisplay_KeyUpKeyCode , Shift
End Sub

Private Sub txtdisplay_Change()
txtdisplay.SelStart = Len(txtdisplay)
End Sub

Private Sub txtdisplay_GotFocus()
txtdisplay_Change
End Sub
--------------------编程问答--------------------
Private Sub cmdequals_Click()
    Dim new_value As Double
    If txtdisplay.Text = "" Then
        new_value = 0
    Else
        new_value = Val(txtdisplay.Text) '这里错误 实时错误 13 类型不匹配
    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
--------------------编程问答-------------------- 试一试 Val(txtdisplay.Text) 吧 --------------------编程问答-------------------- 顶上边的,val转换成数字的 --------------------编程问答-------------------- OK 谢谢 --------------------编程问答-------------------- If IsNumeric(txtdisplay.text)=true then
 new_value = dbl(txtdisplay.Text)
endif --------------------编程问答-------------------- If IsNumeric(txtdisplay.text)=true then
 new_value = cdbl(txtdisplay.Text)
endif 
--------------------编程问答--------------------
引用 4 楼 myshareni 的回复:
OK 谢谢
结贴 --------------------编程问答--------------------
补充:VB ,  资源
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,