Announcement

Collapse
No announcement yet.

strings array and word arrays

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • strings array and word arrays

    Hello
    I have a problem in strings, here is my problem
    My idea was read diferent arrays like

    str1,str2, str3....... strn

    i have declared this arrays in the beginning of the code
    like this

    var str1[20];
    var str1[20];
    .
    .
    .

    now i am using this strings all the time in my code because i have to call them the problem is there are a lot of them, i am new using a 4d system display, and i notice that there is no way to create a 2 dimension array, my code looks like this:

    Code:
    func callp1(var _control,var _n)
        if (_control==1)
            pFile := file_Open("punto1.cfg", 'r');
            latp1[1]:= file_GetW(pFile);latp1[2]:= file_GetW(pFile);latp1[3]:= file_GetW(pFile);
            lonp1[1]:= file_GetW(pFile);lonp1[2]:= file_GetW(pFile);lonp1[3]:= file_GetW(pFile);
            n1:=file_GetS(sbuf1,20,pFile);
            file_Close(pFile);
            print([STR]sbuf1);
            print(" ",[DEC] latp1[1]," ",[DEC] latp1[2],".",[DEC] latp1[3]," S","\t");
            print(" ",[DEC] lonp1[1]," ",[DEC] lonp1[2],".",[DEC] lonp1[3]," W","\n");
        else if (_control==2)
            to(sbuf1); putstr(buffer);
            latp1[1]:=LAT_dd;latp1[2]:=LAT_mm_whole;latp1[3]:=LAT_mm_part;
            lonp1[1]:=LON_dd;lonp1[2]:=LON_mm_whole;lonp1[3]:=LON_mm_part;
            pFile := file_Open("punto1.cfg", 'w');
            file_PutW(latp1[1],pFile);file_PutW(latp1[2],pFile);file_PutW(latp1[3],pFile);
            file_PutW(lonp1[1],pFile);file_PutW(lonp1[2],pFile);file_PutW(lonp1[3],pFile);
            file_PutS(sbuf1,pFile);
            file_Close(pFile);
        else if (control==3)
            latt1[i*n]:=latp1[1];
            latt2[i*n]:=latp1[2];
            latt3[i*n]:=latp1[3];
            lont1[i*n]:=lonp1[1];
            lont1[i*n]:=lonp1[1];
            lont1[i*n]:=lonp1[1];
        endif
    endfunc
    the idea is all the strings and all the single word values all of them are arrays, i have to do this function all the time for every point, because in this case i have 7 values: 1 string and 6 words arrays all of them identified by a number 1 2 3 etc, the number is in my case one point or one data

    There is any way to access the name of the constant name something like this str[identifier][1] this looks like a 2 dimensional array but there is not possible, I have to copy this code 100 times changing the name of the constant???


  • #2
    The easiest way to do multidimensional arrays is something like
    var str0[10] ;
    var str1[10] ;
    var str2[10] ;
    var strs[3] ;
    strs[0] := str0 ;
    strs[1] := str1 ;
    strs[2] := str2 ;
    so the address of str0 ends up in strs[0], etc. you can then says

    strn := strs[0] ;
    and then strn[1] will be the same as str0[1]

    I hope that makes sense.

    Mark

    Comment


    • #3
      Thanks it seems to work but I have to do a large declaration in the begining of the first function because I have like a 100 variables that I am storing in the sd card

      Thanks Mark

      Comment


      • #4
        This is the declaration for the first 3 points
        var stri1[20];
        var stri2[20];
        var stri3[20];
        var strs[3];
        var numlg1,numlg2,numlg3;
        var numlm1,numlm2,numlm3;
        var numls1,numls2,numls3;
        var numlg[3],numlm[3],numls[3];
        var numog1,numog2,numog3;
        var numom1,numom2,numom3;
        var numos1,numos2,numos3;
        var numog[3],numom[3],numos[3];
        var ConfigFile1,Npuntos;
        var i;
        var punto;
        var nombre[20];

        func main()
        strs[1]:=stri1;
        strs[2]:=stri2;
        strs[3]:=stri3;
        numlg[1]:=numlg1; numlg[2]:=numlg2; numlg[3]:=numlg3;
        numlm[1]:=numlm1; numlm[2]:=numlm2; numlm[3]:=numlm3;
        numls[1]:=numls1; numls[2]:=numlm2; numls[3]:=numls3;

        numog[1]:=numog1; numog[2]:=numog2; numog[3]:=numog3;
        numom[1]:=numom1; numom[2]:=numom2; numom[3]:=numom3;
        numos[1]:=numos1; numos[2]:=numom2; numos[3]:=numos3;

        Comment


        • #5
          For the numeric arrays, you can use file_Read to read all elements at once. Assuming, of course, that they are saved as 'binary'
          Mark

          Comment

          Working...
          X