Topic
  • 1 reply
  • Latest Post - ‏2013-07-04T16:33:51Z by VincentBeraudier
HowardGe
HowardGe
9 Posts

Pinned topic how can i automaticaly set the translating rang size of from excel

‏2013-07-04T12:27:46Z |

hi,guys

i came cross a hard work and i need your kindly support.

scenario :

(1) i define the task numbers use the variable "TaskNum"

(2) i need another two variables ,one is one-dimensional array( a[TaskNum] ) and another is  two-dimensional array(  aa[TaskNum][TaskNum] ).The size of both the two varibales is relatived with the variable "TaskNum";

(3)when we want to automatically import data from excel and  set the size of one-dimensional array in opl script , we usually write this:a  from SheetRead (sheet,"Sheet1!A1:A"+TaskNum) ;

here comes the problem ,when i want to translate data from excel to .dat. the ordinate is similar to the one-dimensional array but the abscissa is the character like "a","aa","ac".how can i correspond the charater with the variable  "TaskNum".

Thanks for you anttention and best regards!

 

  • VincentBeraudier
    VincentBeraudier
    4 Posts
    ACCEPTED ANSWER

    Re: how can i automaticaly set the translating rang size of from excel

    ‏2013-07-04T16:33:51Z  

    perhaps:

    <code>

    {string} lettres = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
    "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    int alphabet[lettres] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25, 26];

    string simple = "c";
    string complex = "ac";
    string complex2 = "xfd";
    execute{
      function go(input){
        var mystr = input.toLowerCase();
        var size = mystr.length;
        var sum = 0;
        for (var i = 0; i< size; i++){
              sum *=26;          
            var cc = mystr.charAt(i);
            sum+= alphabet[cc];
                    
        }   
        return sum;
      }    
     
      writeln(go(simple));
      writeln(go(complex));
      writeln(go(complex2));
    }

    </code>

  • VincentBeraudier
    VincentBeraudier
    4 Posts

    Re: how can i automaticaly set the translating rang size of from excel

    ‏2013-07-04T16:33:51Z  

    perhaps:

    <code>

    {string} lettres = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
    "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
    int alphabet[lettres] = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25, 26];

    string simple = "c";
    string complex = "ac";
    string complex2 = "xfd";
    execute{
      function go(input){
        var mystr = input.toLowerCase();
        var size = mystr.length;
        var sum = 0;
        for (var i = 0; i< size; i++){
              sum *=26;          
            var cc = mystr.charAt(i);
            sum+= alphabet[cc];
                    
        }   
        return sum;
      }    
     
      writeln(go(simple));
      writeln(go(complex));
      writeln(go(complex2));
    }

    </code>