Dynamic variable names without EVAL - NEWBIE

Discussion in 'ASP .Net' started by jason@cyberpine.com, Oct 27, 2003.

  1. Guest

    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!
     
    , Oct 27, 2003
    #1
    1. Advertising

  2. wrote:

    > 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...


    --
    Craig Deelsnyder
    Microsoft MVP - ASP/ASP.NET
     
    Craig Deelsnyder, Oct 28, 2003
    #2
    1. Advertising

  3. cesarjusto

    Joined:
    Jul 15, 2010
    Messages:
    1
    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
     
    cesarjusto, Jul 15, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wanwan
    Replies:
    3
    Views:
    432
    Alex Martelli
    Oct 14, 2005
  2. News123
    Replies:
    2
    Views:
    465
    John Machin
    Nov 26, 2008
  3. Replies:
    2
    Views:
    218
    Bob Barrows [MVP]
    Jul 13, 2006
  4. Thairuby Thairuby
    Replies:
    1
    Views:
    112
    Charles Oliver Nutter
    Jun 8, 2008
  5. Peter Buckley
    Replies:
    5
    Views:
    200
    matt neuburg
    Feb 27, 2009
Loading...

Share This Page