Create a Variable from the value of another variable 
Author Message
 Create a Variable from the value of another variable

This may sound crazy but...

Is there a way I can create a vcariable that is named the value of another
variable?

Like this:
say that x = value
after I get this I need to make a new variable in my script named "value" to
store other data
so I can make value = 100 or Somevalue.

This is what I'd like to be able to do:
    x = ts.readline    ' Say x returned "Apple" as an example
    ' i want to be able to do this:
    Set Apple = wscript.Createobject("Scripting.Dictionary") ' set apple
would be from the value of x.
    Apple.add "Something Else"

I want to be able to do it without hard coding the second variables name



Tue, 02 Aug 2005 03:32:27 GMT  
 Create a Variable from the value of another variable
Hi,

Not crazy, and indeed a very useful tool.

If you're using the current version of VBS (v5.6), you
can use the Execute command.  (Execute may have been
introduced in v5.1, I'm not sure).  Execute executes a
script string.

---
x = "y"
Execute x & "= 100"
WScript.Echo y
---

Execute will create a new global variable (despite any
Option Explicit statement), even from a procedure, if
you have not previously Dim'd the variable as a local
or global variable.

Joe Earnest


Quote:
> This may sound crazy but...

> Is there a way I can create a vcariable that is named the value of another
> variable?

> Like this:
> say that x = value
> after I get this I need to make a new variable in my script named "value"
to
> store other data
> so I can make value = 100 or Somevalue.

> This is what I'd like to be able to do:
>     x = ts.readline    ' Say x returned "Apple" as an example
>     ' i want to be able to do this:
>     Set Apple = wscript.Createobject("Scripting.Dictionary") ' set apple
> would be from the value of x.
>     Apple.add "Something Else"

> I want to be able to do it without hard coding the second variables name



Tue, 02 Aug 2005 04:09:48 GMT  
 Create a Variable from the value of another variable
most excellent..
Thank you very much....


Quote:
> Hi,

> Not crazy, and indeed a very useful tool.

> If you're using the current version of VBS (v5.6), you
> can use the Execute command.  (Execute may have been
> introduced in v5.1, I'm not sure).  Execute executes a
> script string.

> ---
> x = "y"
> Execute x & "= 100"
> WScript.Echo y
> ---

> Execute will create a new global variable (despite any
> Option Explicit statement), even from a procedure, if
> you have not previously Dim'd the variable as a local
> or global variable.

> Joe Earnest



> > This may sound crazy but...

> > Is there a way I can create a vcariable that is named the value of
another
> > variable?

> > Like this:
> > say that x = value
> > after I get this I need to make a new variable in my script named
"value"
> to
> > store other data
> > so I can make value = 100 or Somevalue.

> > This is what I'd like to be able to do:
> >     x = ts.readline    ' Say x returned "Apple" as an example
> >     ' i want to be able to do this:
> >     Set Apple = wscript.Createobject("Scripting.Dictionary") ' set apple
> > would be from the value of x.
> >     Apple.add "Something Else"

> > I want to be able to do it without hard coding the second variables name



Tue, 02 Aug 2005 04:56:53 GMT  
 Create a Variable from the value of another variable
ok, it will make a variable, but I need to be able to make an object out of
it
so I can create a dictionary from "x"'s value.

x = "y"
set "y" =  wscript.Createobject("Scripting.Dictionary") '


Quote:
> Hi,

> Not crazy, and indeed a very useful tool.

> If you're using the current version of VBS (v5.6), you
> can use the Execute command.  (Execute may have been
> introduced in v5.1, I'm not sure).  Execute executes a
> script string.

> ---
> x = "y"
> Execute x & "= 100"
> WScript.Echo y
> ---

> Execute will create a new global variable (despite any
> Option Explicit statement), even from a procedure, if
> you have not previously Dim'd the variable as a local
> or global variable.

> Joe Earnest



> > This may sound crazy but...

> > Is there a way I can create a vcariable that is named the value of
another
> > variable?

> > Like this:
> > say that x = value
> > after I get this I need to make a new variable in my script named
"value"
> to
> > store other data
> > so I can make value = 100 or Somevalue.

> > This is what I'd like to be able to do:
> >     x = ts.readline    ' Say x returned "Apple" as an example
> >     ' i want to be able to do this:
> >     Set Apple = wscript.Createobject("Scripting.Dictionary") ' set apple
> > would be from the value of x.
> >     Apple.add "Something Else"

> > I want to be able to do it without hard coding the second variables name



Tue, 02 Aug 2005 05:15:34 GMT  
 Create a Variable from the value of another variable
Hi,

If I understand what you want to do ...

x = "y"
Execute "set " & x _
  & " =  wscript.Createobject(""Scripting.Dictionary"")"

This will give you an object "y".  (Note the need for the
double-quotes for quotes inside a string.)

Joe Earnest


Quote:
> ok, it will make a variable, but I need to be able to make an object out
of
> it
> so I can create a dictionary from "x"'s value.

> x = "y"
> set "y" =  wscript.Createobject("Scripting.Dictionary") '



> > Hi,

> > Not crazy, and indeed a very useful tool.

> > If you're using the current version of VBS (v5.6), you
> > can use the Execute command.  (Execute may have been
> > introduced in v5.1, I'm not sure).  Execute executes a
> > script string.

> > ---
> > x = "y"
> > Execute x & "= 100"
> > WScript.Echo y
> > ---

> > Execute will create a new global variable (despite any
> > Option Explicit statement), even from a procedure, if
> > you have not previously Dim'd the variable as a local
> > or global variable.

> > Joe Earnest



> > > This may sound crazy but...

> > > Is there a way I can create a vcariable that is named the value of
> another
> > > variable?

> > > Like this:
> > > say that x = value
> > > after I get this I need to make a new variable in my script named
> "value"
> > to
> > > store other data
> > > so I can make value = 100 or Somevalue.

> > > This is what I'd like to be able to do:
> > >     x = ts.readline    ' Say x returned "Apple" as an example
> > >     ' i want to be able to do this:
> > >     Set Apple = wscript.Createobject("Scripting.Dictionary") ' set
apple
> > > would be from the value of x.
> > >     Apple.add "Something Else"

> > > I want to be able to do it without hard coding the second variables
name



Tue, 02 Aug 2005 05:40:24 GMT  
 Create a Variable from the value of another variable
you got it.
I now have a script that creates multiple Dictionaries (based on the header
name) out of an ini file.

Thank you very much for getting me off the learning curve on this one.
I appreciate it..


Quote:
> Hi,

> If I understand what you want to do ...

> x = "y"
> Execute "set " & x _
>   & " =  wscript.Createobject(""Scripting.Dictionary"")"

> This will give you an object "y".  (Note the need for the
> double-quotes for quotes inside a string.)

> Joe Earnest



> > ok, it will make a variable, but I need to be able to make an object out
> of
> > it
> > so I can create a dictionary from "x"'s value.

> > x = "y"
> > set "y" =  wscript.Createobject("Scripting.Dictionary") '



> > > Hi,

> > > Not crazy, and indeed a very useful tool.

> > > If you're using the current version of VBS (v5.6), you
> > > can use the Execute command.  (Execute may have been
> > > introduced in v5.1, I'm not sure).  Execute executes a
> > > script string.

> > > ---
> > > x = "y"
> > > Execute x & "= 100"
> > > WScript.Echo y
> > > ---

> > > Execute will create a new global variable (despite any
> > > Option Explicit statement), even from a procedure, if
> > > you have not previously Dim'd the variable as a local
> > > or global variable.

> > > Joe Earnest



> > > > This may sound crazy but...

> > > > Is there a way I can create a vcariable that is named the value of
> > another
> > > > variable?

> > > > Like this:
> > > > say that x = value
> > > > after I get this I need to make a new variable in my script named
> > "value"
> > > to
> > > > store other data
> > > > so I can make value = 100 or Somevalue.

> > > > This is what I'd like to be able to do:
> > > >     x = ts.readline    ' Say x returned "Apple" as an example
> > > >     ' i want to be able to do this:
> > > >     Set Apple = wscript.Createobject("Scripting.Dictionary") ' set
> apple
> > > > would be from the value of x.
> > > >     Apple.add "Something Else"

> > > > I want to be able to do it without hard coding the second variables
> name



Wed, 03 Aug 2005 05:00:43 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Create a Variable from the value of another variable

2. passing javascript variable into asp variable using vbscript

3. Object variable or With block variable not set (Error 91)

4. Object variable or With Block variable not set

5. Splitting Session Variable into several variables (array?)

6. Largest Variable for the Long variable type

7. Redirection Problem (VBScript variable to JavaScrip variable)

8. Variable data/variable print

9. Assigning Client Script Variables to Application level variables inside of a Client Script

10. variables naming variables

11. Adding Environmental Variable to System Variables thru VB

12. Reassign a request variable to another request variable?

 

 
Powered by phpBB® Forum Software