VB编程的一段程序

来源:百度知道 编辑:UC知道 时间:2024/05/25 05:00:43
Private Sub Command2_Click()

Dim i As Integer
i = List2.ListIndex
If i = 0 Then
Text3.Text = Val(Text1.Text) + Val(Text2.Text)

ElseIf i = 1 Then
Text3.Text = Val(Text1.Text) - Val(Text2.Text)

ElseIf i = 2 Then
Text3.Text = Val(Text1.Text) * Val(Text2.Text)

ElseIf i = 3 Then
Text3.Text = Val(Text1.Text) / Val(Text2.Text)

ElseIf i = 4 Then
Text3.Text = Val(Text1.Text) ^ Val(Text2.Text)

ElseIf i = 5 Then
Text3.Text = Sin(Text1.Text)

ElseIf i = 6 Then
Text3.Text = Cos(Text1.Text)

ElseIf i = 7 Then
Text3.Text = Tan(Text1.Text)

ElseIf i = 8 Then
Text3.Text = cot(Text1.Text)

ElseIf i = 9 Then
Text3.Text = Val(Text1.Text) \ Val(Text2.Text)

ElseIf i = 10 Then
Text3.Text = Val(Text1.Text) Mod Val(Text2.Text)

End Sub
那位大哥帮我看看哪错了啊

vb中没有函数cot
你想要cot只能是自己定义,通过那个sin和cos推导,
如:Mycos=Cos(30) '返回弧度30的余弦值
那摩mycot=Cos(30)/Sin(30) ‘就是cot的值了

Text3.text只能是字符串啊,你看看你的后面,是数值。应该写作这样:
Text3.Text = str(Val(Text1.Text) Mod Val(Text2.Text)
)

1 把余切函数改为正切函数的倒数
Text3.Text = 1/tan(Text1.Text)

2 在if函数末尾,也就是End Sub 上面添加 end if

3 建议在初始化的时间 List2.ListIndex 取零,默认加法。如下:
Private Sub Form_Load()
List2.ListIndex = 0
End Sub

4 不知你有无对List2进行了初始化,如果没有的话,可以采用方法.AddItem。例如下面语句
List2.AddItem "+"
List2.AddItem "-"
List2.AddItem "×"
List2.AddItem "÷"

一个endif都没有吧