1,105,417 Community Members

vb6's execute() function in vb.net

Member Avatar
josverhoeff
Newbie Poster
13 posts since Jan 2013
Reputation Points: 6 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

I am (still) converting an old asp web app / vb6 dll to aspx / vb.net
I am now biting on a fairly simple function in vbscript: the execute() function
What the vbscript does is the following: It reads in a variable name and its (string) value from a database in a loop.
The variables were then created and set to the value by calling the execute functio:

here is a code snippet:

read....
do while ...
        strVarName = ds("varname")
        strVarValue = ds("varvalue")
        call execute(strVarName=""" & strVarValue & """")
loop

after this there existed a variable with the name and value as requested
In vb.net I would like to do something similar. I will have to declare all possible variables I suppose, but it would be nice to be able to keep the loop.

If not I'll have to recode a fill procedure that assigns all values, but maybe someone here has a good suggestion

Member Avatar
Begginnerdev
Veteran Poster
1,142 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
0
 

Can you have something like this:

Do While True
    strVarName = ds.Tables("MyTable")(iRow)("varname")
    strVarValue = ds.Tables("MyTable")(iRow)("varvalue")
    If Execute(strVarName, strVarValue) Then Exit Do
    'If the function returns True, the loop will exit.
Loop

Private Function Execute(ByVal sVarName As String, ByVal sVarValue As String) As Boolean
    'Your code here
End Function

Or am I grossly misunderstanding the question?

Member Avatar
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418 [?]
Q&As Helped to Solve: 152 [?]
Skill Endorsements: 16 [?]
 
1
 

after this there existed a variable with the name and value as requested

This sounds like a key-value pair to me. Perhaps a Dictionary will work.

Member Avatar
Reverend Jim
Noli mentula
5,444 posts since Aug 2010
Reputation Points: 746 [?]
Q&As Helped to Solve: 653 [?]
Skill Endorsements: 51 [?]
Moderator
Featured
 
0
 

vbScript had the functions, Execute and ExcecuteGlobal which allowed runtime execution of VB expressions (strings) with various levels of scoping. As I recall, this feature is not available in VB.net 2010 but might be have been restored in VB.net 2012. If you really need to execute dynamic code then you might look into VB 2012. If you don't mind handling the dynamic expressions yourself (ie maintaining your own symbol table) then TnTinMN's suggestion is likely your best bet.

Member Avatar
Ancient Dragon
Achieved Level 70
27,637 posts since Aug 2005
Reputation Points: 5,232 [?]
Q&As Helped to Solve: 3,037 [?]
Skill Endorsements: 115 [?]
Team Colleague
Featured
Sponsor
 
0
 

Maybe this will help????

Member Avatar
TnTinMN
Practically a Master Poster
640 posts since Jun 2012
Reputation Points: 418 [?]
Q&As Helped to Solve: 152 [?]
Skill Endorsements: 16 [?]
 
0
 

If it's dynamic code execution, then that can be handled via CodeDom and compile on the fly. Not to difficult to do, but takes some setup to get right.

But based on my understanding of the OP's stated situation, it looks like just some value that needs to be referenced by name.

Member Avatar
josverhoeff
Newbie Poster
13 posts since Jan 2013
Reputation Points: 6 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hm, I'm sure I marked this as solved two days ago.
Anyway, the dictionary solution was the one that matched closest. I still had to replace the hundtred or so of calls to doSomethingwith(VarName) with doSomethingwith(Mydictionarylist("varname")), but I have become quite proficient at search./.replace using regular expressions

Thanx for all the suggestions

Question Answered as of 1 Year Ago by TnTinMN, Ancient Dragon, Begginnerdev and 1 other
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: