首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行时错误9:数组

运行时错误9:数组
EN

Stack Overflow用户
提问于 2014-08-21 03:06:50
回答 1查看 27关注 0票数 0

我是新手的VBA编程,并试图为RCC设计开发一个简单的代码。大多数值都是直接从excel工作表分配的。我得到这个错误,说*中的“被零除”.The行在调试时被高亮显示。似乎声明或循环有一些问题,但我不能确定。请帮帮忙。提前谢谢。代码如下:

代码语言:javascript
复制
    Private Sub CommandButton1_Click()
    Dim a As Double, b As Double, result As String, Mu As Double
    Dim i As Integer, j As Integer, c As Integer, Xu1, Xu, es, d, f, fs As Double
    Dim strain1(1 To 6) As Double, stress1(1 To 6) As Double 
    a = Range("E30").Value
    b = Range("O30").Value
    If a < b Then
       result = "Under Reinforced Section"
       Mu = Range("E32").Value * Range("E34").Value
    ElseIf a = b Then
       result = "Balanced Secction"
       Mu = Range("E32").Value * Range("E34").Value
    ElseIf a > b Then
       result = "Over Reinforced Section"
       j = 31
       For i = 1 To 6
         strain1(i) = Cells(j, 7)// loop to assign values in array from excel sheet
         j = j + 1
       Next
     j = 31
       For i = 1 To 6
         stress1(i) = Cells(j, 8)
         j = j + 1
       Next
       c = 1
       Xu1 = Range("O30").Value
       d = Range("E31").Value
       Do While c = 1
         Xu = Xu1
         **es = 0.0035 * (d - Xu) / (Xu)**// Shows error apparently Xu is taking value zero
         If Range("E22").Value = 250 Then
            fs = es * Range("E23").Value
            f = 0.87 * Range("E22").Value
            If fs > f Then
               fs = f
            End If
         ElseIf Range("E22").Value = 415 Then
            f = 0.696 * Range("E22").Value / Range("E23").Value
            If es > f Then
               For i = 1 To 6
                If es > strain1(i) And es < strain1(i + 1) Then// to locate es in the array and then interpolate
                 fs = stress1(i) + ((stress1(i + 1) - stress1(i)) / (strain1(i + 1) - strain1(i))) * (es - strain1(i))// linear interpolation formulae
                End If
               Next
            ElseIf es < f Then
               fs = es * Range("E23").Value
            End If
            Xu1 = Range("O29").Value * fs / (0.36 * Range("E21").Value * Range("E16").Value)
            If Xu1 = Xu Then
              c = 0
            End If
            Mu = 0.36 * Range("E21").Value * Range("E16").Value * Xu1 * Range("E34").Value
         End If
       Loop
     End If
     Range("O21").Value = Mu
     MsgBox result
     End Sub
EN

回答 1

Stack Overflow用户

发布于 2014-08-21 03:44:01

strain1(1到6)有6个元素1到6,对于i=6,您试图访问高亮显示行中的第7个元素(strain1(i + 1))。(下一行中的stress1也是如此)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25412573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档