Public Sub BC(F, E3, N0, M1, Ec, Es)B = Val(Text1(0).Text)
H = Val(Text2.Text)
T1 = Val(Text3(0).Text)
R = Val(Text5.Text)
fc = Val(Text4(0).Text)
ft = Val(Text15.Text)
a = Val(Text8.Text)
Es = Val(Text9.Text)
As1 = Val(Text10.Text)fy = 300
E0 = 0.002                                    For I = 0 To T1 - 1 Step 1
Z = I * H / T1 + H / (2 * T1)
E = E3 + F * Z                               y = E / E0If E <= -0.0033 Then                          
s = 0
ElseIf y < -1 Then
s = -fc
ElseIf y >= -1 And y <= 0 Then
y = Abs(y)
s = -fc * (1 - (1 - y) ^ 2)
ElseIf E > 0 And E <= 0.0001 Then             
s = ft * (2 * E / (E + 0.0001))
ElseIf E > 0.0001 And E <= 0.00015 Then
s = ft
ElseIf E > 0.00015 Then
s = 0
ElseIf E > 0 Then
s = 0
End IfNc = Nc + s * B * H / T1
Mc = Mc + Abs(s * B * H * Abs(H / 2 - Z) / T1)NextEc = E - H * FZ = H - a
E = E3 + Z * F
If E > 0.01 Then
s = 0
ElseIf E > 0.0015 Then
s = fy
ElseIf E <= 0.0015 Then
s = E * Es
End If
Ns = Abs(s * As1)
Ms = Abs(s * As1 * (Z - H / 2))
Es = E
N0 = Nc + Ns
M1 = Mc + MsEnd Sub
Private Sub Command1_Click()                  H = Val(Text2.Text)
a = Val(Text8.Text)
N = CDbl(Text5.Text)
M0 = CDbl(Text7.Text)
Dim F As Double, d As Double, c As Double, a1 As Double, a2 As Double, a3 As Double
Dim b1 As Double, b2 As Double, b3 As Double, E3 As Double, N0 As Double, M1 As Double    F = 0.00000001
    d = 0.00000001
For W = 0 To 500 Step 1
    
    c = -0.0033
    
  For K = 0 To 100 Step 1    E3 = c
    Call BC(F, E3, N0, M1, Ec, Es)
    a1 = CDbl(N0 + N)
    E4 = N0
        
    E3 = c + 0.0001
    Call BC(F, E3, N0, M1, Ec, Es)  '调用bc
    a2 = CDbl(N0 + N)
    E5 = N0
    
    E3 = c - 0.0001 * a1 / (a2 - a1)  '除数为零,此时K=1
    Call BC(F, E3, N0, M1, Ec, Es)
    a3 = N0 + N    If Abs(a3) < 50 Then
    Exit For
    Else
    c = E3
    End If
    
  Next K
  
    b1 = M1 - M0
    
    F = d + 0.0000001
    F = Abs(F)
    Call BC(F, E3, N0, M1, Ec, Es)
    b2 = M1 - M0
    
    If b1 = b2 Then
    Exit For
    End If
    
    F = d - 0.0000001 * b1 / (b2 - b1)
    F = Abs(F)
    Call BC(F, E3, N0, M1, Ec, Es)
    b3 = M1 - M0    If Abs(a3) < 50 And Abs(b3 / M0) < 0.0001 Then
    Exit For
    Else
    d = F
    End If
    
    E1 = Ec
    E2 = Es
    
Next W
    
Text6.Text = Round(E1, 5)
Text14.Text = Round(E2, 5)
Text12.Text = Round(F, 8)
Text13.Text = Round(M1, 2)
Text17.Text = E5
End Sub

解决方案 »

  1.   

    出错信息是什么?
    在IDE中调试运行有没有出错, 不是逐语句那种, 而是直接F5
      

  2.   

        E3 = c - 0.0001 * a1 / (a2 - a1)  '除数为零,此时K=1
        Call BC(F, E3, N0, M1, Ec, Es)
        a3 = N0 + N运行时,当K=1时,也就是说循环进行一圈后,E3的式子中,a2=a1,导致除数为零;但逐语句运行9圈后,a2与a1也没有出现相等的情况。
    所以问题就是,程序整体运行出错,但逐语句运行没有错误。
      

  3.   

        E3 = c - 0.0001 * a1 / (a2 - a1)  '除数为零,此时K=1
        Call BC(F, E3, N0, M1, Ec, Es)
        a3 = N0 + N出错信息就是:除数为零