Private Sub Command1_Click()
Dim x1 As Double, y1 As Double, r As Double, x2 As Double, y2 As Double, r1 As Double, r2 As Double
r1 = 50: r2 = 70: r = 0
x1 = Text1.Text: x2 = Text3.Text: y1 = Text2.Text: y2 = Text4.TextDo While Abs(chaoyue(x1, y1, x2, y2, r)) > 0.00001
r = (r1 + r2) / 2
If chaoyue(x1, y1, x2, y2, r) = 0 Then Text5.Text = r
Else
      If chaoyue(x1, y1, x2, y2, r) < 0 Then r1 = r
      Else: r2 = r
      End If
      
End If
Loop
Text5.Text = r
End Sub这个一直提示else无if  why????
大侠们@!

解决方案 »

  1.   

    If chaoyue(x1, y1, x2, y2, r) = 0 Then Text5.Text = r
    写到一行就表示是一个完整的if语句,后面没有else或endif
      

  2.   

    把IF...then...改成
    IF...then
    ....
      

  3.   

    兄弟,少了一个if,当然提示了!Private Sub Command1_Click()
    Dim x1 As Double, y1 As Double, r As Double, x2 As Double, y2 As Double, r1 As Double, r2 As Double
    r1 = 50: r2 = 70: r = 0
    x1 = Text1.Text: x2 = Text3.Text: y1 = Text2.Text: y2 = Text4.TextDo While Abs(chaoyue(x1, y1, x2, y2, r)) > 0.00001
        r = (r1 + r2) / 2
        If chaoyue(x1, y1, x2, y2, r) = 0 Then 
            Text5.Text = r
        Else
            If chaoyue(x1, y1, x2, y2, r) < 0 Then 
                r1 = r
            Else
                r2 = r
            End If
        End If
    LoopText5.Text = r
    End Sub
      

  4.   

    If chaoyue(x1, y1, x2, y2, r) = 0 Then Text5.Text = r
    Else
      If chaoyue(x1, y1, x2, y2, r) < 0 Then r1 = r
      Else: r2 = r
      End If
    改为以下的试试:
    If chaoyue(x1, y1, x2, y2, r) = 0 Then
      Text5.Text = r
    Else
      If chaoyue(x1, y1, x2, y2, r) < 0 Then r1 = r Else r2 = r
    End If