views:

163

answers:

1

Hi There

I hope someone can help me with the following...

I have this code below it is written in classic asp and javascript...

I have this variable in the code below my2String1 how can I make this a dynamic variable like:

  • my2String1_1
  • my2String1_2
  • my2String1_3

I have a database value Recordset2.Fields.Item("article_no").Value which could be the dynamic value like:

my2String1_Recordset2.Fields.Item("article_no").Value (which should do the trick) but I am not sure how to implement it...

while((Repeat1__numRows-- != 0) && (!Recordset2.EOF)) { 
    var my2String1 = ""+(Recordset2.Fields.Item("article_description").Value)+"";
    my2String = my2String1;
    var my2regexp = new RegExp(checkduplicates, "ig"); 
    my2Array = my2String1.match(my2regexp);
    my2length = my2Array.length;

    for (i = 0; i < my2length; i++) {
        my2Array[i] = '\''+my2Array[i]+'\'';
    }

    var arr = (myArray+my2Array).split(',');  
    var sorted_arr = arr.sort();
    var results = [];

    for (var i = 0; i < arr.length - 1; i += 1) { 
        if (sorted_arr[i + 1] == sorted_arr[i]) { 
            results.push(sorted_arr[i]); 
        }
    } 

    Repeat1__index++;
    Recordset2.MoveNext();
}

If you have any ideas on how to solve this please help me

+1  A: 

I'm going to ignore that load of code because it clouding the issue. The feature of JScript you are looking to for is the ability to create named properties on an object:-

var myDescriptions = {}

var name = "Test"
var description = "This is a test" 

myDescriptions[name] = description;

Response.Write(myDescriptions[name]);

Would send "This is a test" to the response.

AnthonyWJones
I am still struggling with this, but I think your solution is helpfull. My result response is the same for all my results? is there a way that I can call a spesific result by Response.Write(myDescription[test1]) and getting the value for test 1 - and then maybe call myDescription[test2]) and get the value for it ?
Gerald Ferreira
@Gerald: It might help if you edit your question with a description of what your code is actually trying to do. If you describe the input recordsets and the desired output we can probably give you a more complete solution and describe the techniques used in the process.
AnthonyWJones
after implementing the solution on all variables it is now working perfectly - I only did a replacement on one variable but the others needed to change as well
Gerald Ferreira