By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,730 Members | 1,648 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,730 IT Pros & Developers. It's quick & easy.

Look Up Table Help

P: 30
Here is my code for look up table - where i am planning to built 10 colums and 8 rows and put [x,y] array values in the table boxes. Problem is - it is only printing the last array valules instead of all

Expand|Select|Wrap|Line Numbers
  1.     var maxRow = 10;
  2.     var maxCol = 8;
  3.     var height1 = 480;
  4.     var width1 = 640;
  5.  
  6. function CenteringError(Xe, Ye){
  7.  
  8. var table = new Array             ( ([5,0],    [2,-3],    [2,-3],    [1,-2],    [0,-2],    [0,-1],    [1,-1],    [1,-1],    [0,-1],    [-5,2]),
  9.                                                             ([3,-2],   [-1,-3],   [-1,-3],   [1,-2],    [-1,-2],   [1,-1],    [1,-1],    [2,-2],    [2,-2],    [-3,-1]),
  10.                                                             ([1,-3],   [-2,-3],   [-2,-3],   [-2,-2],   [-1,-2],   [0,0],     [1,-1],    [2,-1],    [2,-1],    [1,-2]),
  11.                                                             ([-2,0],   [-2,-1],   [-2,-1],   [-2,0],    [-1,0],    [1,0],     [2,0],     [2,0],     [2,0],     [2,0]),
  12.                                                             ([-2,-1],  [-2,-1],   [-2,-1],   [-2,0],    [-1,0],    [1,0],     [3,0],     [2,1],     [2,1],     [2,0]),
  13.                                                             ([-1,1],   [-2,0],    [-2,0],    [-2,1],    [-1,1],    [1,1],     [2,1],     [2,1],     [2,2],     [1,2]),
  14.                                                             ([-1,2],   [-2,1],    [-2,1],    [-2,1],    [-1,2],    [-1,1],    [1,1],     [1,3],     [1,2],     [-2,3]),
  15.                                                             ([4,1],    [0,0],     [-1,0],    [-1,0],    [-1,0],    [0,2],     [0,1],     [-1,2],    [-1,3],    [-4,2])
  16.                                                         );
  17. var correct = [0,0];
  18.  
  19. //this math function gets mouse pos and builts Rows and Colums in Viewer
  20.  
  21. correct[0] = table[Math.round((maxRow* Ye)/height1)];
  22. correct[1] = table[Math.round((maxCol* Xe)/width1)];
  23.  
  24. var x = correct[0];
  25. var y = correct[1];
  26.  
  27. alert(x + "     " + y);
  28. }
  29.  
I am alerting x and y values but it only prints certain numbers and repeats it. This program is not working properly. I dont know why.

Help would be appreciated...

Thanks
May 14 '08 #1
Share this Question
Share on Google+
2 Replies


rnd me
Expert 100+
P: 427
change your parens to array brackets and try again.
May 15 '08 #2

acoder
Expert Mod 15k+
P: 16,027
Harshpandya, please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future. Thanks!
May 15 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.