繁体   English   中英

Java脚本的新功能。 如何使用应用程序脚本将我的VBA自定义函数转换为在工作表中工作

[英]New to java script. How to convert my vba custom function to work in sheets using app scriptor

我正在尝试根据我的VBA代码在Google表格中创建自己的自定义函数,但无法正常工作。

   Function MyRandBetween(lowint As Long, highint As Long) As Long
        Randomize 
        MyRandBetween = Round(lowint + Rnd() * (highint - lowint), 0)
        End Function

您只需要使用Math.random()。

Google表格中的示例:

function myFunction() {
    var sheet = SpreadsheetApp.getActiveSheet();   
  SpreadsheetApp.getActiveSheet().getRange('A1').setValue(MyRandBetween(1,100));
}


function MyRandBetween(low, high) {
    return Math.floor(Math.random() * high) + low;
}

脚本:

在此处输入图片说明

结果:

在此处输入图片说明

 // Function MyRandBetween(lowint As Long, highint As Long) As Long // Randomize // MyRandBetween = Round(lowint + Rnd() * (highint - lowint), 0) // End Function const getRandom = (low, hi) => { return Math.round(low + Math.random() * (hi - low)); }; console.log(getRandom(1, 10)); console.log(getRandom(30, 100)); console.log(getRandom(20, 30)); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM