473,394 Members | 1,769 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,394 software developers and data experts.

Dynamically execute a Sub, possibly with help of "ScriptControl"

[The language is VB6, but as it's about implementing dynamic call of
another method from the same module with the ScriptControl object, it
shouldnt matter too much..]

Hi,

I'd like to do something like that (see explanations after the code
snippet) :

Sub mainSub (foo as String)
Dim msScript As New ScriptControl
msScript.Language = "VBScript"
Dim someVar as String 'that'll be a parameter for the secondary sub
someVar = "blah"
Dim statement As String 'that's gonna be the dynamic statement to
execute
statement = foo & "_otherSub " & blah
'"reality check" call, equivalent to what I want, but static:
two_otherSub "blah"
'The thing...:
msScript.execute(statement) 'Using: foo = "two"
end Sub

Sub one_otherSub (bar as string)
'do something
end Sub

Sub two_otherSub (bar as string)
'do something
end Sub

I'd like to use that because:
mainSub takes a table name as parameter, fills a recordset with it and
exports it to a flat file. Now, if I can have different subs for the
formatting of the FIELDS of the recordset (when I write to file) and
call these subs dynamically depending on the table name parameter, then
I don't need anymore hard code in the mainSub... (like a big ugly
SELECT CASE with 100 branches)

Is that possible? Am I on the right track? I made some tries but
without success, an hour of googling without much success either.
Besides, I don't know whether I should use the .Eval, or .Run or
..Execute method..

If it helps to picture the case, here are the signatures:

1) moduleName.export(tableName As String)
The calling statement (in its "passive" form):
For Each fld In rs.Fields
TABLE_NAME_formatFields outFile, fld
Next

2) TABLE_NAME_formatFields(outFile As moduleName.outFile, fld)
Here's how it's handeld:
With outFile
Select Case fld.Name
Case "FIELD_1": .AddToLine 0, fld.value, 5
Case "FIELD_2": .AddToLine 2, fld.value, 25
'etc. for each field..
End Select
End With

NB: outFile's type is a class I made, where .AddToLine is working like
this:
AddToLine(spaceBefore as Integer, content as String, fieldLength as
Integer)

Thanks, bye!

Nov 21 '05 #1
1 2567
One day, sj******@gmail.com wrote:
[The language is VB6, but as it's about implementing dynamic call of
another method from the same module with the ScriptControl object, it
shouldnt matter too much..]

<snippedy-doo-dah>

On the contrary, it's a one-liner in VB .NET!

You may have better luck asking your question in one of the VB-classic
groups, microsoft.public.vb.*

Hope this helps!

--
Tom Spink
Nov 21 '05 #2

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

Similar topics

0
by: Grant Gardiner | last post by:
This is an interesting one... You have a Word document with a parent table. Inside this is another table. This subtable has 4 columns, where I need to dynamically insert FormFields into each...
4
by: finlma | last post by:
I'm trying to run an EXECUTE IMMEDIATE within a PL/SQL if loop but it doesn't work for me. I'm trying to create a column conditionally but it doesn't work. It fails because there are apostrophes...
3
by: Agoston Bejo | last post by:
I am looking for the PL/SQL equivalent of the VBScript Exec and/or Eval functions, i.e. I want to be able to dynamically create a statement, then execute it in the current PL/SQL context, e.g. ...
6
by: Doohan W. | last post by:
Hi, I'm now working with DB2, and I can't find out how to execute the contents of a string Statement, without using a Java/... procedure, only using SQL statements. I know that some SQBDs such...
3
by: John Crowley | last post by:
I've run into a problem where drop down lists are refusing to data bind with the following error on the DataBind() call Specified argument was out of the range of valid values. Parameter name:...
5
by: WebMatrix | last post by:
Hello, I am developing ASP.NET 1.1 application against SQL Server 2000 db, where users have ability to construct their own select criteria (for a where clause). I already developed a user...
1
by: Crash | last post by:
Hi, ..NET v1.x SP1 VS 2003 SQL Server 2000 SP3 Server 2000, XP, Server 2003 I would like to programmatically execute {possibly many} SQL Server batch scripts. Aka I have many scripts that...
0
by: jad2006 | last post by:
i created CREATE PROCEDURE SP_STMT_STMTRETRIEVE10(IN p_client_id varchar(32) ,IN p_TIN varchar(32)) P1: BEGIN DECLARE p_customer_id varchar(32); DECLARE stmt VARCHAR(100); DECLARE cursor1...
1
by: ngeluis | last post by:
I all, this is my first time that im using google groups so i dont know how it work.. but i'm going to try anyway :P I have build a application on Vb.net 2005 Framework 2.0. That application is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.