Declare a variable inside your program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • djpaul
    New Member
    • Oct 2006
    • 137

    #1

    Declare a variable inside your program

    Hello,
    I am busy making a program to create scripts.
    In there i also want to use variables.
    But how can i declare a new variable just by entering a name and selecting a type (eg, string, int, float etc) on a form??

    Thanks!
    Paul
  • GaryTexmo
    Recognized Expert Top Contributor
    • Jul 2009
    • 1501

    #2
    I'm afraid I'm not sure I understand your question...

    Like, your form has a textbox on it in which you write a script and your program will parse it? You want to know how to handle variable storage?

    If that's the case, the easiest way might be to create a data type that stores the name, type, and value of your variable... something like:

    Code:
    struct Variable
    {
      string name;
      Type type;
      object value;
    }
    Then your code can store a list of these (updating per scope, I'd imagine). When you execute the code, I think you might be able to make use of reflection... have a look into that.

    Comment

    Working...