How to get Results from ParseScriptText call 
Author Message
 How to get Results from ParseScriptText call

I am having problem understanding the VB Script Engine API .  I cannot seem
to
get the VB Script to return a result in the pvarResult pointer.  I have in
my code:

        VARIANT* pVarJan;

I then allocate the real VARIANT, and since I don't know how big I might
need it
I allocate some memory and cast it as the VARIANT like:

         if (pVarJan == 0)
          pVarJan = (VARIANT*)CoTaskMemAlloc(4096);

         if (pVarJan == 0) // alloc failed
          return E_OUTOFMEMORY;

Then issue the call to the VB Script Engine (dwFlags = 0).

HRESULT hr = STDCOMCALL(m_pActiveScriptParse, ParseScriptText(
  pstrCode,
  pstrItemName,
  punkContext,
  pstrEndDelimiter,
  dwSourceContextCookie,
  ulStartingLineNumber,
  dwFlags,
  pVarJan,
  pexcepinfo));

I know the script executes (because I get an error when I purposely put in a
syntax error), but I always get back VT_EMPTY in the VARIANT.  My VBScript
looks like:

    Function Eval()
        Eval = "Hello from Script"
    End Function

    Eval

So how do I get the script engine to give me back the "Hello from Script"
string?  Even if I initialize the pVarJan as a string, it still returns
empty.  Does anyone know what should be different?

Jan Wiewiora
Unisys Corporation



Sun, 27 May 2001 03:00:00 GMT  
 How to get Results from ParseScriptText call
Try changine the last line of your script from
        Eval
to
        Eval()

I don't know if this will work, but in general you use parentheses when
using the return value from a function in VBScript.  It's possible that
the result is being thrown away since you're calling Eval as though it
were a procedure.

There may be something else wrong, but this may be worth a shot.
                                                        Larry

Quote:

> I am having problem understanding the VB Script Engine API .  I cannot seem
> to
> get the VB Script to return a result in the pvarResult pointer.  I have in
> my code:

>         VARIANT* pVarJan;

> I then allocate the real VARIANT, and since I don't know how big I might
> need it
> I allocate some memory and cast it as the VARIANT like:

>          if (pVarJan == 0)
>           pVarJan = (VARIANT*)CoTaskMemAlloc(4096);

>          if (pVarJan == 0) // alloc failed
>           return E_OUTOFMEMORY;

> Then issue the call to the VB Script Engine (dwFlags = 0).

> HRESULT hr = STDCOMCALL(m_pActiveScriptParse, ParseScriptText(
>   pstrCode,
>   pstrItemName,
>   punkContext,
>   pstrEndDelimiter,
>   dwSourceContextCookie,
>   ulStartingLineNumber,
>   dwFlags,
>   pVarJan,
>   pexcepinfo));

> I know the script executes (because I get an error when I purposely put in a
> syntax error), but I always get back VT_EMPTY in the VARIANT.  My VBscript
> looks like:

>     Function Eval()
>         Eval = "Hello from Script"
>     End Function

>     Eval

> So how do I get the script engine to give me back the "Hello from Script"
> string?  Even if I initialize the pVarJan as a string, it still returns
> empty.  Does anyone know what should be different?

> Jan Wiewiora
> Unisys Corporation




Sat, 09 Jun 2001 03:00:00 GMT  
 How to get Results from ParseScriptText call
Jan,

Try somthing like this:
CComVariant res;
hr = m_asp->ParseScriptText( L"Function Eval(): Eval = \"Hello from
Script\": End Function", 0, 0, 0, 0, 0, 0, &res, &ei );
if( SUCCEEDED( hr ) ) {
        hr = m_asp->ParseScriptText( L"Eval", 0, 0, 0, 0, 0,
SCRIPTTEXT_ISEXPRESSION, &res, &ei );
        if( SUCCEEDED( hr ) && res.vt == VT_BSTR ) {
                MessageBoxW( 0, res.bstrVal, L"TestHost script result", MB_OK |
MB_ICONERROR );
        }

Quote:
}



Quote:
>Try changine the last line of your script from
> Eval
>to
> Eval()

>I don't know if this will work, but in general you use parentheses when
>using the return value from a function in VBScript.  It's possible that
>the result is being thrown away since you're calling Eval as though it
>were a procedure.

>There may be something else wrong, but this may be worth a shot.
> Larry


>> I am having problem understanding the VB Script Engine API .  I cannot
seem
>> to
>> get the VB Script to return a result in the pvarResult pointer.  I have
in
>> my code:

>>         VARIANT* pVarJan;

>> I then allocate the real VARIANT, and since I don't know how big I might
>> need it
>> I allocate some memory and cast it as the VARIANT like:

>>          if (pVarJan == 0)
>>           pVarJan = (VARIANT*)CoTaskMemAlloc(4096);

>>          if (pVarJan == 0) // alloc failed
>>           return E_OUTOFMEMORY;

>> Then issue the call to the VB Script Engine (dwFlags = 0).

>> HRESULT hr = STDCOMCALL(m_pActiveScriptParse, ParseScriptText(
>>   pstrCode,
>>   pstrItemName,
>>   punkContext,
>>   pstrEndDelimiter,
>>   dwSourceContextCookie,
>>   ulStartingLineNumber,
>>   dwFlags,
>>   pVarJan,
>>   pexcepinfo));

>> I know the script executes (because I get an error when I purposely put
in a
>> syntax error), but I always get back VT_EMPTY in the VARIANT.  My
VBscript
>> looks like:

>>     Function Eval()
>>         Eval = "Hello from Script"
>>     End Function

>>     Eval

>> So how do I get the script engine to give me back the "Hello from Script"
>> string?  Even if I initialize the pVarJan as a string, it still returns
>> empty.  Does anyone know what should be different?

>> Jan Wiewiora
>> Unisys Corporation




Sun, 10 Jun 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Getting a URL Call result into a string?

2. calling dll func, getting wrong result...

3. To Call or not to Call - test results

4. getting results with InputBox

5. Problem Executing WSH script and getting a result with ASPExec

6. getting results with InputBox

7. Getting results from WshShell.Run

8. Piping results of command line call to file from ASP

9. no results-call asp pg using WSH

10. Piping results of command line call to file from ASP

11. ParseScriptText

12. DefineScriptBlock() & ParseScriptText() failing

 

 
Powered by phpBB® Forum Software