初始化数组

时间:2015-10-01 13:53:42

标签: arrays excel vba excel-vba

我有一个数组,它应该在Excel的整个生命周期中保持不变的值。 当我尝试用数字初始化我的数组时,我收到错误“无效的外部过程”:

$('.select2').change(function(e){         
    var arraypos = $(this).children(":selected").attr("id");
        jQuery.ajax({
            url: '/wallfly-mvc/public/dashboard/selectedProperty',
            type: "POST",
            data: {
                selected: arraypos
            },
            success: function (result) {
                $('#showoption').attr('id');
                window.location.reload();
            },
            error: function (result) {
                alert('Exeption:' + exception);
            }
        });
});

2 个答案:

答案 0 :(得分:0)

在模块Module1中

Private ar As Variant
Function Aone(idx As Integer) As Double
    On Error GoTo FillArray
    Aone = ar(idx)
    Exit Function
FillArray:
    ar = Array(0.47589, 0.23795, 0.16656, 0.16656, 0.03569, 0.04759, 0.00119, 0.00119, 0.00119)
    Aone = ar(idx)

End Function

答案 1 :(得分:0)

好吧终于找到了解决方案,

正如@ A.S.H建议的那样,但没什么变化:

at" ThisWorkbook"模块

Sub Workbook_Open()
    Aone(1) = 0.47589
    Aone(2) = 0.23795
    Aone(3) = 0.16656
    Aone(4) = 0.16656
    Aone(5) = 0.03569
    Aone(6) = 0.04759
    Aone(7) = 0.00119
    Aone(8) = 0.00119
    Aone(9) = 0.00119

谢谢大家