Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 运行时错误9:数组_Excel_Vba - Fatal编程技术网

Excel 运行时错误9:数组

Excel 运行时错误9:数组,excel,vba,Excel,Vba,我是VBA编程新手,正在尝试为RCC设计开发一个简单的代码。大多数值直接从excel工作表中指定。我得到的错误是“除零”。调试时,****内的行高亮显示。声明或循环似乎存在一些问题,但我无法确定。请帮忙。提前准备好。代码如下: Private Sub CommandButton1_Click() Dim a As Double, b As Double, result As String, Mu As Double Dim i As Integer, j As Integ

我是VBA编程新手,正在尝试为RCC设计开发一个简单的代码。大多数值直接从excel工作表中指定。我得到的错误是“除零”。调试时,****内的行高亮显示。声明或循环似乎存在一些问题,但我无法确定。请帮忙。提前准备好。代码如下:

    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
Private子命令按钮1\u单击()
Dim a为双精度,b为双精度,结果为字符串,Mu为双精度
Dim i为整数,j为整数,c为整数,Xu1,Xu,es,d,f,fs为双精度
尺寸应变1(1至6)为双精度,应力1(1至6)为双精度
a=范围(“E30”).值
b=范围(“O30”).值
如果ab呢
结果=“过度加固截面”
j=31
对于i=1到6
strain1(i)=单元格(j,7)//循环从excel工作表中指定数组中的值
j=j+1
下一个
j=31
对于i=1到6
压力1(i)=细胞(j,8)
j=j+1
下一个
c=1
Xu1=范围(“O30”).值
d=范围(“E31”).值
当c=1时,请执行此操作
Xu=Xu1
**es=0.0035*(d-Xu)/(Xu)**//显示Xu取零值的错误
如果范围(“E22”)。值=250,则
fs=es*范围(“E23”).值
f=0.87*范围(“E22”).值
如果fs>f,那么
fs=f
如果结束
ElseIf范围(“E22”)。值=415
f=0.696*范围(“E22”).值/范围(“E23”).值
如果es>f,那么
对于i=1到6
如果es>应变1(i)且es<应变1(i+1),则//在阵列中定位es,然后进行插值
fs=应力1(i)+(应力1(i+1)-应力1(i))/(应变1(i+1)-应变1(i))*(es-应变1(i))//线性插值公式
如果结束
下一个
如果是,那么
fs=es*范围(“E23”).值
如果结束
Xu1=范围(“O29”).值*fs/(0.36*范围(“E21”).值*范围(“E16”).值)
如果Xu1=Xu,那么
c=0
如果结束
Mu=0.36*范围(“E21”)。值*范围(“E16”)。值*范围(“E34”)。值
如果结束
环
如果结束
范围(“O21”)。值=μ
MsgBox结果
端接头

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

对于i=1到5而不是i=1到6+1,Xu现在取0,尽管调试的右侧显示了正确的值。