TScriptControl - Werte an Funktionen übergeben



  • Hallo,

    ich habe hoffentlich ein kleines Problem. Ich möchte an ein VBS-Programm Parameter übergeben. Das Problem ist nun, das die Parameter nicht richtig an das VBS-Programm übergeben werden, zurückgegeben wird aber ein Wert.

    Hoffe Ihr könnt mir weiterhelfen.

    Variant rueck;
    LPSAFEARRAY psa;
    SAFEARRAYBOUND rgsabound[1];
    
    rgsabound[0].cElements = 2;
    rgsabound[0].lLbound = 0;
    
    psa = SafeArrayCreate(VT_VARIANT , 1, rgsabound);
    
    long n=0;
    SafeArrayPutElement(psa,&n,SysAllocString(OLESTR("Test1")));
    n++;
    SafeArrayPutElement(psa,&n,SysAllocString(OLESTR("Test2")));
    
    ScriptControl1->AddCode(L"Function Test(Text1,Text2)\nMsgBox \"Text \" & Text1\nTest=\"Rückantwort\"\nEnd Function");
    rueck= ScriptControl1->Run(L"Test",&psa);
    
    AnsiString ruecktext= rueck.operator AnsiString();
    


  • Hallo,

    so jetzt habe ich die Lösung gefunden.

    Variant rueck;
        Variant in[2];
        LPSAFEARRAY psa;
        SAFEARRAYBOUND rgsabound[] = {2,0};
    
        psa = SafeArrayCreate(VT_VARIANT , 1, rgsabound);
    
        if ( !psa ) return ;
    
        Variant help1 = "1000";
        Variant help2 = "2000";
        in[0] = Variant(SysAllocString(help1));
        in[1] = Variant(SysAllocString(help2));
    
        long n=0;
        SafeArrayPutElement(psa,&n,&in[0]);
        n++;
        SafeArrayPutElement(psa,&n,&in[1]);
    
        ScriptControl1->Language = "VBScript";
        ScriptControl1->AddCode(L"Function Test(Text1,Text2)\nMsgBox \"Text \" & Text1*Text2\nTest=Text1*Text2\nEnd Function");
        //ScriptControl1->Language = "JScript";
        //ScriptControl1->AddCode(L"function Test(Text1,Text2)\n{return Text2+Text1;}");
        rueck= ScriptControl1->Run(L"Test",&psa);
    
        AnsiString ruecktext= rueck.operator AnsiString();
    
        SafeArrayDestroy(psa);
        CoUninitialize();
    

Anmelden zum Antworten