mbt masai
 
Welcome !
         

                                
After experiencing a lot of down time, We decided to move this site to CrystalTech.com. CrystalTech.com is powered by only the finest Windows servers providing the best performance, reliability, and value anywhere.

 Problem with execute command

Author Message
tjodalv

  • Total Posts : 5
  • Scores: 0
  • Reward points : 0
  • Joined: 12/4/2009
  • Status: offline
Problem with execute command Friday, December 04, 2009 1:25 AM (permalink)
0
Hello

I want to create variable dynamically in runtime, so I tried to use Execute command but I always get an error saying:
Expected end of statement

This is what I am trying to do:

x = "my_variable_name"
y = "this is variable value"

Execute(x & " = " & y) '<- Error is in this line

Response.Write my_variable_name


When I try to execute class than it's working fine for eg. like this:

my_class_var = "blog"
class_name = "cBlog"
Execute("set " &
my_class_var & " = New " & class_name)

Can anyone help me pls.
#1
    centauricw

    • Total Posts : 42
    • Scores: 2
    • Reward points : 0
    • Joined: 2/20/2006
    • Status: offline
    Re:Problem with execute command Friday, December 04, 2009 1:59 AM (permalink)
    0
    You cannot create a variable dynamically.  The statement Execute( x & " = " & y) fails because what you are really doing is an assignment statement between two strings as your statement is actually this:

      Execute( "my_variable_name" & " = " & "this is variable value" )

    which is the same as

      "my_variable_name" = "this is variable value"

    therefore the error message: Microsoft VBScript compilation error: Expected end of statement

    <message edited by centauricw on Friday, December 04, 2009 2:00 AM>
    #2
      tjodalv

      • Total Posts : 5
      • Scores: 0
      • Reward points : 0
      • Joined: 12/4/2009
      • Status: offline
      Re:Problem with execute command Friday, December 04, 2009 2:06 AM (permalink)
      0
      Yes but then I could write just like this: my_variable_name = this is variable value

      What is the point of Execute then. I need to create variables dynamically.
      #3
        tjodalv

        • Total Posts : 5
        • Scores: 0
        • Reward points : 0
        • Joined: 12/4/2009
        • Status: offline
        Re:Problem with execute command Friday, December 04, 2009 3:14 AM (permalink)
        0
        I've managed to solve the problem this is magic line :D

        Execute(x & "=""" & y & """")
        #4
          ebgreen

          • Total Posts : 8088
          • Scores: 95
          • Reward points : 0
          • Joined: 7/12/2005
          • Status: offline
          Re:Problem with execute command Friday, December 04, 2009 3:28 AM (permalink)
          0
          I will point out that I have yet to have anyone show me a case where execute is required for dynamic variables. With the information that you have provided, a dictionary would work just fine with no need for the use of execute at all. Execute is bad in a purely client side script. In a web environment, it is anathema.
          "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
          Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
          http://www.visualbasicscript.com/m_47117/tm.htm
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.8
            mbt shoes www.wileywilson.com