none
convert Javascript to VBscript RRS feed

  • Question


  • I've got a Javascript (JS) that I'd like to convert into a VBscript (VBS).

    Unfortunately I am not able to find a sort of a translation from JS to VBS for math-functions.

    I hope someone might have an idea about how to best perform this taks and appreciate your feedback.

    Thanks, Carlos.

    Here is the JS script:

    function LogGamma(Z) {
    with (Math) {
    var S=1+76.18009173/Z-86.50532033/(Z+1)+24.01409822/(Z+2)-1.231739516/(Z+3)+.00120858003/(Z+4)-.00000536382/(Z+5);
    var LG= (Z-.5)*log(Z+4.5)-(Z+4.5)+log(S*2.50662827465);
    }
    return LG
    }

    function Betinc(X,A,B) {
    var A0=0;
    var B0=1;
    var A1=1;
    var B1=1;
    var M9=0;
    var A2=0;
    var C9;
    while (Math.abs((A1-A2)/A1)>.00001) {
    A2=A1;
    C9=-(A+M9)*(A+B+M9)*X/(A+2*M9)/(A+2*M9+1);
    A0=A1+C9*A0;
    B0=B1+C9*B0;
    M9=M9+1;
    C9=M9*(B-M9)*X/(A+2*M9-1)/(A+2*M9);
    A1=A0+C9*A1;
    B1=B0+C9*B1;
    A0=A0/B1;
    B0=B0/B1;
    A1=A1/B1;
    B1=1;
    }
    return A1/A
    }

    function compute(Z,A,B) {
        with (Math) {
    if (A<=0) {
    alert("alpha must be positive")
    } else if (B<=0) {
    alert("beta must be positive")
    } else if (Z<=0) {
    Betacdf=0
    } else if (Z>=1) {
    Betacdf=1
    } else {
    S=A+B;
    BT=exp(LogGamma(S)-LogGamma(B)-LogGamma(A)+A*log(Z)+B*log(1-Z));
    if (Z<(A+1)/(S+2)) {
    Betacdf=BT*Betinc(Z,A,B)
    } else {
    Betacdf=1-BT*Betinc(1-Z,B,A)
    }
    }
    Betacdf=Betacdf+.000005
            s = Betacdf
    }
    return s
    }

    function BuscarAlfa(ObjetivoMenor60)
    {
    var Alfa = 2;
    var Beta = 2;
    var A = 0;
    var B = 1;
    var NivelConfianza = 0.97;
    var DistrBetas;
    var DistrMonetaria;
    var DistrBetasMonetaria;
    var iteraciones = 0;

    DistrBetas = compute(ObjetivoMenor60,Alfa,Beta)

    if (DistrBetas >= NivelConfianza) {
    while (DistrBetas >= NivelConfianza) {
    DistrBetas = compute(ObjetivoMenor60,Alfa,Beta)
    Alfa = Alfa + 0.0001
    }
    } else {
    while (DistrBetas <= NivelConfianza) {
    DistrBetas = compute(ObjetivoMenor60,Alfa,Beta)
    Alfa = Alfa - 0.0001
    }
    }

    return Alfa
    }

    function BuscarBeta(Alfa, ObjetivoAlDia, Cartera)
    {
    var Beta = 2;
    var DistrMonetaria;
    var DistrBetasMonetaria;

    DistrMonetaria = ObjetivoAlDia * Cartera
    DistrBetasMonetaria = compute(ObjetivoAlDia, Alfa, Beta) * Cartera

    if (DistrBetasMonetaria <= DistrMonetaria) {
    while (DistrBetasMonetaria <= DistrMonetaria) {
    DistrBetasMonetaria = compute(ObjetivoAlDia, Alfa, Beta) * Cartera
    if (DistrBetasMonetaria >= DistrMonetaria) {
        break
        }
    Beta = Beta + 0.0001
    }
    } else {
    while (DistrBetasMonetaria >= DistrMonetaria) {
    DistrBetasMonetaria = compute(ObjetivoAlDia, Alfa, Beta) * Cartera
    if (DistrBetasMonetaria <= DistrMonetaria) {
        break
    }
    Beta = Beta - 0.0001
    }
    }

    return Beta

    }

    • Moved by Bill_Stewart Tuesday, December 5, 2017 3:13 PM This is not "scripts on demand"
    Wednesday, October 25, 2017 10:51 PM

All replies