473,396 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Return Value From VBScript In .NET

I am using an MSScriptControl in vb.net to do an evaluation of a text
string:
tempAnswer = MyScriptControl.Eval(MyScriptString)

But how can I use this to get a return value from a vbscript function:

Function Foo() As Integer
If MyValue = 1 Then
Foo=1
Else
Foo=2
End
End Function

tempCode = "Code Above - Read From A Database"
tempAnswer = MyScriptControl.Run(tempCode)

Do I use the Run command. I do not see a return statement in vbscript. Can
this be done in vb.net?


Oct 21 '08 #1
1 5745
"Derek Hart" wrote:
I am using an MSScriptControl in vb.net to do an evaluation of a text
string:
tempAnswer = MyScriptControl.Eval(MyScriptString)

But how can I use this to get a return value from a vbscript function:

Function Foo() As Integer
If MyValue = 1 Then
Foo=1
Else
Foo=2
End
End Function

The above is not valid VBScript code. You can not declare function return
type and the If statement needs the closing End if.

tempCode = "Code Above - Read From A Database"
tempAnswer = MyScriptControl.Run(tempCode)

Do I use the Run command. I do not see a return statement in vbscript. Can
this be done in vb.net?

MSScriptControl.Run() has a return value and you can use it to run a
VBScript function and get the return value:
Dim objSC As Object
objSC = CreateObject _
("MSScriptControl.ScriptControl")
objSC.Language = "VBScript"

Dim strCode As String
strCode = "Function Foo(intVal)" & vbCrLf _
& "If intVal = 1 Then " & vbCrLf _
& "Foo = 1 " & vbCrLf _
& "Else" & vbCrLf _
& "Foo = 2" & vbCrLf _
& "End If" & vbCrLf _
& "End Function"

objSC.AddCode(strCode)

Dim objRetVal As Object

For i = 0 To 20
objRetVal = objSC.Run("Foo", i)
Console.WriteLine(objRetVal)
Next

Console.ReadLine()
--
urkec
Oct 22 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: tshad | last post by:
I am trying to set up a class to handle my database accesses. I can't seem to figure out how to get the return value from my dataReader from these routines (most of which I got elsewhere). They...
10
by: Ocean | last post by:
I'm a novice on ASP using VBScript, and I encountered a problem when I want to get and use a return value of a web method in my ASP code. There is a web method called "getQuote", which takes a...
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
8
by: solomon_13000 | last post by:
The code bellow functions well. However if I want to obtain a return value using the code bellow, how is it done? <% Sub RunQueryString (pSQL,parms) on error resume next Set conn =...
6
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document...
2
by: philip | last post by:
hello, i am new to asp.net and sql server, and i have 3 questions for asking: 1. i am writing a store procedure of login validation for my asp.net application and wondering what the different...
7
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function...
12
by: Dooza | last post by:
I have a stored procedure that takes a number of inputs, does a bulk insert, and then outputs a recordset. When I run the stored procedure in Server Management Studio I also get a return value from...
1
by: Derek Hart | last post by:
I am using an MSScriptControl in vb.net to do an evaluation of a text string: tempAnswer = MyScriptControl.Eval(MyScriptString) But how can I use this to get a return value from a vbscript...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.