新手小试牛刀!
刚学VB6.0不到三天,急不可耐的自己在一位前辈的指导下写了个解一元二次方程的软件,非常简单的那种,高手就莫笑了,大家给评论评论!Private Sub Command1_Click()
Dim a
Dim b
Dim c
Dim result As Double
Text4.Text = ""
a = Text1.Text
b = Text2.Text
c = Text3.Text
If IsNumeric(a) And IsNumeric(b) And IsNumeric(c) Then
result = ABC(a, b, c)
Text4.Text = Text4.Text
Else
MsgBox ("请在a,b,c三个文本框中输入数字系数!")
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End Sub
Function ABC(a, b, c)
Dim x1 As Double, x2 As Double
Dim delta As Double
delta = b * b - 4 * a * c
If a <> 0 Then
If delta < 0 Then
Text4.Text = Text4.Text & "方程无实根"
Else
x1 = (-b + Sqr(delta)) / (2 * a)
x2 = (-b - Sqr(delta)) / (2 * a)
Text4.Text = "x1=" & x1 & vbCrLf & "x2=" & x2
End If
ElseIf b <> 0 Then
x1 = c / b
Text4.Text = Text4.Text & "方程有一次根" & vbCrLf & "x=" & x1
Else
If c <> 0 Then
Text4.Text = Text4.Text & "方程无根"
Else
Text4.Text = Text4.Text & " 方程有一个零根 x=0"
End If
End If
End Function
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
由于偶没什么美术功底,所以界面不是很好,背景图片选大了点,耗了几MB的内存。另外还有个问题,我想在前面的数字判断功能上改一下,让a,b,c三个文本框中如果有不是数字的在点击计算时直接将它清零,而不会将是数字的给清理掉,我试着用if 结构,可是改来改去总有那么一点问题,具体情况请各位大虾们在附件中看看,指点指点,不胜感激……