Dynamic variable names without EVAL - NEWBIE

J

jason

I'd like to write an asp.net-VB subroutine that accepts the name of an
itemlist as a parm to be populated. I think under classic ASP I would
use EVAL() to accomplish dynamic code like this. How would I do this
in ASP.NET-VB?


For example in the code below I'd like pass nnnnnn in. Of course this
code as-is will not work.


<vb code snippet>

sub loaditems(nnnnnn as string, regstring as string)

Dim regexp as Regex = New Regex(regstring, RegexOptions.IgnoreCase)
Dim objMatch as Match
dim z as string
For Each objMatch in regexp.Matches(session("readin"))
z = objMatch.ToString()
nnnnnn.items.add(z)
Next
end sub

</vb code?>

Many Thanks in Advance for any help or info!
 
C

Craig Deelsnyder

I'd like to write an asp.net-VB subroutine that accepts the name of an
itemlist as a parm to be populated. I think under classic ASP I would
use EVAL() to accomplish dynamic code like this. How would I do this
in ASP.NET-VB?


For example in the code below I'd like pass nnnnnn in. Of course this
code as-is will not work.


<vb code snippet>

sub loaditems(nnnnnn as string, regstring as string)

Dim regexp as Regex = New Regex(regstring, RegexOptions.IgnoreCase)
Dim objMatch as Match
dim z as string
For Each objMatch in regexp.Matches(session("readin"))
z = objMatch.ToString()
nnnnnn.items.add(z)
Next
end sub

</vb code?>

Many Thanks in Advance for any help or info!

There is no eval statement in VB.NET. I believe only JScript.NET
supports it. A couple of people have made workarounds though

http://www.codeproject.com/dotnet/evaluator.asp?target=evaluator
http://www.codeproject.com/csharp/runtime_eval.asp?target=evaluator

there are others on that site as well...
 
Joined
Jul 15, 2010
Messages
1
Reaction score
0
Code:
Dim i As Integer
        Dim field As System.Reflection.FieldInfo
        Dim lblruc As Label
        For i = 1 To psComReg.Length() - 1
            field = Me.GetType().GetField("lbl_5_" + i.ToString(), System.Reflection.BindingFlags.NonPublic Or System.Reflection.BindingFlags.Instance)
            lblruc = DirectCast(field.GetValue(Me), Label)
            lblruc.Text = psComReg(i - 1)
        Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top