Creating Dynamic Variable

Results 1 to 3 of 3

Thread: Creating Dynamic Variable

  1. #1
    Join Date
    Dec 1969

    Default Creating Dynamic Variable

    Does anyone know how to create variable dynamically.<BR>For example assume I have an array of people and for each of them I want to create a variable e.g.<BR><BR>Dim pple<BR>pple = Array("Chris", "John", "Mark")<BR>For i = 0 to UBound(pple)<BR> Dim pple(i)<BR>Next<BR><BR>I would then be able to say<BR>Chris = "Hunt"<BR>John = "Stockley"<BR>Mark = "Smith"<BR><BR>Obviously this doesn&#039;t work but does anyone know how to do this kind thing.

  2. #2
    Join Date
    Dec 1969

    Default RE: Creating Dynamic Variable

    You should be able to use the VBScript Execute function:<BR><BR>Dim pple<BR>pple = Array("Chris", "John", "Mark")<BR>For i = 0 to UBound(pple)<BR>Execute "Dim " & pple(i)<BR>Next<BR>

  3. #3
    Join Date
    Dec 1969

    Default But don't do it!

    If you are doing this, *SOMETHING* in your program design is wrong, wrong, wrong.<BR><BR>So now you have those N dynamically defined variables. So now how does THE REST OF YOUR PAGE know which ones were defined and when to use them?????<BR><BR>95% of the time, you do *NOT* want dynamic simply want an array.<BR><BR>4.9% of the time, you might want to use a "collection" (in VBS, implemented as Scripting.Dictionary).<BR><BR>The other 0.01% of the time...<BR><BR>Well, let me put it this way: I have NOT YET (in over 18 months!) seen ONE SINGLE correct and effective use of dynamic variables in Server Side VBScript code. EVERY SINGLE TIME when somebody *thought* they needed them, it was a mistake.<BR><BR>Would you care to try to prove to be the exception to the rule? I&#039;ll be brutal, but I&#039;ll be honest. If you can show CODE that correctly and needfully needs them, I&#039;ll owe you a lunch.<BR><BR>[I didn&#039;t say I&#039;d buy you one...I just said I&#039;d owe it to you. &#060;grin/&#062; ]<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