4 Replies Latest reply on Jul 23, 2010 6:06 AM by Matt FTW

    using an array with a function

    Matt FTW

      Hi all,


      I'm working on an order form where users choose a course they want to order from a drop-down list, then enter the number of licences they require. I'm trying to build in a 'volume-based' discount model the form, and would like to ask for some help in using arrays and how to use them in functions. I'm very new to this, and would appreciate any help you can provide!


      Basically, we have 3 products that can be ordered on the same form, and all have different discount models (i.e you get a different % discount for different numbers of licences ordered, depending on the course chosen). I'm storing the discount models in 3 separate two-dimensional arrays, then want to create a function that takes two parameters - the name of the array and the volume that the customer orders - to calculate the appropriate discount. I would then call the function on the change events of either the drop down list or the licence qty field.


      Below is my attempt so far (only one array here, but the others are the same syntax). This is held in a script object called DiscountCalculator in the form. The idea of the function is to loop through the array until it finds the correct course, then loop through the value field until it finds the correct discount:


      //code holds the discount model for each course in a 2 dimensional array. A new array is needed for each course.

      //Course 1



      Course1Array = new Array(3);


      = new Array(2);


      = "49";  //'breakpoint' at which discount is applied


      = "0";   //discount % given for this no of licences


      = new Array(2);


      = "99";


      = "20";


      = new Array(2);


      = "199";


      = "25";





      CalculateDiscount(CourseArray, value){



      (var i = 0; i <= CourseArray.length; i++)




      (value <= CourseArray[i][0])



      return CourseArray[i][1]






      I can use a MessageBox to return a specified value from the array on the click event, so that seems to be set up correctly. But when I try to tcall the function in the change event of the drop-down list on the form:


      DiscountCalculator.CalculateDiscount(fldCourse.rawvalue, fldqty.rawvalue)


      It doesn't work, usually complaining that "Course1Array is not defined". I think it must be some kind of syntax error, but I have trawled the internet looking for some examples and can't find any.


      I'd be grateful for any assistance.