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

vb中else 和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.Text

Do 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????
大侠们@! --------------------编程问答-------------------- If chaoyue(x1, y1, x2, y2, r) = 0 Then Text5.Text = r
写到一行就表示是一个完整的if语句,后面没有else或endif --------------------编程问答-------------------- 把IF...then...改成
IF...then
....
--------------------编程问答-------------------- 兄弟,少了一个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.Text

Do 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
--------------------编程问答-------------------- 少了还不止一个啊 --------------------编程问答-------------------- 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 --------------------编程问答--------------------
引用 2 楼 chunaii 的回复:
把IF...then...改成
IF...then
....

正解!
补充:VB ,  非技术类
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,