求高手在此指导一下
实时错误'13'
类型不匹配。
问题语句:current = Text1.Text
全部代码:
Public choice As String
Public current As Double
Public prev As Double
Public counter As Integer
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub ac_Click()
Text1.Text = ""
prev = current = 0
'dz.Visible = False
'asterisk.Enabled = False
'equal.Enabled = False
'expo.Enabled = False
'logn.Enabled = False
'logten.Enabled = False
'minus.Enabled = False
'plus.Enabled = False
'sign.Enabled = False
'slash.Enabled = False
'sroot.Enabled = False
'cosine.Enabled = False
'sine.Enabled = False
'tangent.Enabled = False
'invsine.Visible = False
'invcos.Visible = False
'invtan.Visible = False
'expo.Visible = False
End Sub
Private Sub asterisk_Click()
Text1.Text = ""
choice = "*"
prev = current
current = 0
End Sub
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
current = Text1.Text
asterisk.Enabled = True
equal.Enabled = True
expo.Enabled = True
' logn.Enabled = True
' logten.Enabled = True
minus.Enabled = True
plus.Enabled = True
sign.Enabled = True
slash.Enabled = True
sroot.Enabled = True
' tangent.Enabled = True
'' cosine.Enabled = True
' sine.Enabled = True
End Sub
Private Sub Command3_Click()
Dim MyAngle, MyHSin
MyAngle = 1.3 ' 定义角度(以"弧度"为单位)
MsgBox (Exp(MyAngle) - Exp(-1 * MyAngle)) / 2 ' 计算双曲正弦函数值(sin())
End Sub
Private Sub cosine_Click()
Text1.Text = Cos(current * 3.14159265358979 / 180)
current = Cos(current * 3.14159265358979 / 180)
End Sub
Private Sub equal_Click()
On Error GoTo MyErr
If choice = "+" Then
current = prev + current
Text1.Text = current
ElseIf choice = "-" Then
current = prev - current
Text1.Text = current
ElseIf choice = "*" Then
current = prev * current
Text1.Text = current
ElseIf choice = "/" And current <> 0 Then
current = prev / current
Text1.Text = current
Else
Text1.Text = "Press AC to continue"
dz.Visible = True
dz.Caption = "Division by ZERO"
End If
If current < 0 Then
sroot.Enabled = False
Else
sroot.Enabled = True
End If
Exit Sub
MyErr:
MsgBox Err.Description, vbInformation, "信息提示"
End Sub
Private Sub expo_Click()
On Error GoTo MyErr
Exit Sub
MyErr:
MsgBox Err.Description, vbInformation, "信息提示"
End Sub
Private Sub expo10_Click()
Dim i As Integer
Dim j As Double
j = current
current = 1
For i = 1 To j Step 1
current = current * 10
Next i
Text1.Text = current
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim value As Integer
End Sub
Private Sub invcos_Click()
Dim temp As Double
temp = current * 3.14159265358979 / 180
If (temp <= 1 And temp >= -1) Then
Text1.Text = 1 / Cos(temp)
current = 1 / Cos(temp)
End If
invsine.Visible = False
invcos.Visible = False
invtan.Visible = False
expo.Visible = False
expo10.Visible = False
End Sub
Private Sub invsine_Click()
Dim temp As Double
temp = current * 3.14159265358979 / 180
If (temp <= 1 And temp >= -1) Then
Text1.Text = 1 / Sin(temp)
current = 1 / Sin(temp)
End If
End Sub
Private Sub invtan_Click()
Text1.Text = 1 / Tan(current * 3.14159265358979 / 180)
current = 1 / Tan(current * 3.14159265358979 / 180)
invsine.Visible = False
invcos.Visible = False
invtan.Visible = False
expo.Visible = False
expo10.Visible = False
End Sub
Private Sub logn_Click()
Text1.Text = Log(current)
current = Log(current)
End Sub
Private Sub logten_Click()
Text1.Text = Log(current) / Log(10)
current = Log(current) / Log(10)
End Sub
Private Sub mode_MouseDown(Button As Integer, shift As Integer, X As Single, Y As Single)
counter = counter + 1
If counter > 2 Then
counter = 1
End If
If counter = 2 Then
displaylb.Caption = "Normal Calculator"
displaylb.ForeColor = &HFFC0C0
Form1.Width = 4830
sine.Visible = False
cosine.Visible = False
tangent.Visible = False
logn.Visible = False
logten.Visible = False
random.Enabled = False
random.Visible = False
shiftb.Visible = False
recall.Visible = False
Else
displaylb.Caption = " Scientific Calculator"
displaylb.ForeColor = &HC0&
Form1.Width = 5670
sine.Visible = True
cosine.Visible = True
tangent.Visible = True
logn.Visible = True
logten.Visible = True
random.Enabled = True
random.Visible = True
shiftb.Visible = True
recall.Visible = True
End If
End Sub
Private Sub point_Click()
If Text1.Text = "" Then
Text1.Text = "0."
Else
Text1.Text = Text1.Text & "."
End If
End Sub
Private Sub random_Click()
Text1.Text = (2.1021020134 * Rnd + 1)
End Sub
Private Sub recall_Click()
Text1.Text = current
End Sub
Private Sub shiftb_Click()
invsine.Visible = True
invcos.Visible = True
invtan.Visible = True
expo.Visible = True
expo10.Visible = True
If Text1.Text <= 1 And Text1.Text >= -1 Then
invsine.Enabled = True
invcos.Enabled = True
End If
invtan.Enabled = True
expo.Enabled = True
expo10.Enabled = True
End Sub
Private Sub sign_Click()
If current < 0 Then
Text1.Text = -current
current = -current
Else
Text1.Text = "-" & Text1.Text
current = -current
End If
If current < 0 Then
sroot.Enabled = False
Else
sroot.Enabled = True
End If
End Sub
Private Sub minus_Click()
Text1.Text = ""
choice = "-"
prev = current
current = 0
End Sub
Private Sub plus_Click()
Text1.Text = ""
choice = "+"
prev = current
current = 0
End Sub
Private Sub sine_Click()
Text1.Text = Sin(current * 3.14159265358979 / 180)
current = Sin(current * 3.14159265358979 / 180)
End Sub
Private Sub slash_Click()
Text1.Text = ""
choice = "/"
prev = current
current = 0
End Sub
Private Sub sroot_Click()
On Error GoTo MyErr
Text1.Text = Sqr(current)
current = Sqr(current)
Exit Sub
MyErr:
MsgBox Err.Description, vbInformation, "信息提示"
End Sub
Private Sub tangent_Click()
Text1.Text = Tan(current * 3.14159265358979 / 180)
current = Tan(current * 3.14159265358979 / 180)
End Sub
[解决办法]
Public current As Double
current = Text1.Text
'text1中输入的类型不匹配,就算输入个空格也不行的。
你限制text输入的内容或者修改current定义的类型就可以了
[解决办法]
private sub text1_lostfocus()
if trim(text1.text)<>"" then
if not isnumeric(text1.text) then
msgbox "请输入数值型数据!",48,"提示"
text1.setfocus
exit sub
else
current=text1.text
end if
else
current=0
end if
end sub