VBScript problem! dynamic variables??

Results 1 to 2 of 2

Thread: VBScript problem! dynamic variables??

  1. #1
    Jonas Hernlund Guest

    Default VBScript problem! dynamic variables??

    Hello!<BR><BR>I&#039m trying to figure out a way to make my script to work...<BR>I have a lot of arrays called: count1, count2, count3 etc.<BR>I want to use a sort of dynamic variable naming..<BR>example code:<BR><BR>for i = 1 to 3 <BR><BR> count&i(this is where i want to create the variable: "count1")= something<BR><BR><BR>next <BR><BR><BR>Ïs this possible to do? The nearest thing is to use some multi dimensioned arrays but I don&#039t really like that idea..<BR>

  2. #2
    Join Date
    Dec 1969

    Default dynamically named variables inadvisable

    If you are trying to use dynamically named variables, you are *probably* doing something wrong.<BR><BR>After all, when it comes time to get values out of those variables, how do you know WHAT variables you have? You end up having to have another variable just to keep track of them! Or worse.<BR><BR>More than likely, an array--even a multi-dimensioned array--is far the better choice.<BR><BR>You could also look into using the Scripting.Dictionary object: You add a value to a dictionary, giving it a "key" that is, for all intents and purposes, a dynamic name for the value.<BR><BR>FINALLY...<BR><BR>If you really *must* do this, then VBScript version 5 added the "eval" function. You could use it. Fair warning: It is a performance hog.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts