Announcement

Collapse
No announcement yet.

Array of arrays of string arrays

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

  • John Kevin
    replied
    Hello markl,

    Let's say you have an array that can store up to 5 values, and you have declared a constant values to each index.
    Code:
    var Array0[5]:=[1,2,3,4,5];
    using the print function
    Code:
    print([DEC]Array0[5]," ");
    you will get a value of 0 because in memory address '5' there are no values stored.

    But if you have another set of arrays/variables declared below
    Code:
    var Array0[5]:=[1,2,3,4,5];
    var Array1[5]:=[6,7,8,9,10];
    using the print function
    Code:
    print([DEC]Array0[5]," ");
    you will get a value of 6 because you are pointing your memory address at '5'
    which is equivalent to the data stored.

    using the print function
    Code:
    print([DEC]Array1[0]," ");
    you will also get a value of 6 because your variable "Array1" has an
    address starting from 0.


    Now given this function:
    Code:
     var Data[2];
    you are saying that there are 2 allocated addresses.

    using the function
    Code:
    Data[0]:= Array0;
    Data[1]:= Array1;
    you are storing the memory address of Array0 to Data[0] and
    memory address of Array1 to Data[1]. By having '5 memory address'
    allocated to Array0, the next address will be '6' on which is
    the address of Data[1].

    Note: This is to assume that there are no variables declared
    aside from this two.


    Then using the function:
    Code:
     Arrays:=Data[0];
    you are now getting the addresses stored.

    And if you are indexing the Arrays using the command
    Code:
     print(Arrays[0]);
    this will yield to value equivalent to Array[0].

    Error: global variable 'Arrays' can only be initialized with a constant value (line 23 column 11 file:Magiccode1.inc)
    That is because you are declaring "Arrays:=Data[0]" on global declaration,
    you can add that on your main function or other functions.

    You can also try this type of declaration:
    Code:
    var Array0[24];
    var Array1[24];
    var Data[2] := [Array0,Array1];
    var Arrays;
    And just call this line on your function.
    Code:
    Arrays:=Data[0];
    I hope this helps.
    Best Regards,
    Kevin

    Leave a comment:


  • markl
    replied
    Thank you for your reply, I
    got the following error when I tried this:
    Error: global variable 'Arrays' can only be initialized with a constant value (line 23 column 11 file:MagicCode1.inc)

    I don't understand one thing though, when you set Data[0] := Array0, is that declaring the entire array Array0[24] = to Data[0]? I thought that declaring Array0 and Array0[24] would not be allowed because you are declaring the same variable two different ways, Array0[24], and Array0. And what about Arrays = to Data[0], what about Data[1] ? Shouldn't Arrays be equal to Data[2]? Is this something unique to 4dgl?

    Thanks for your help,

    Mark
    Last edited by markl; 28th July 2018, 10:55 PM.

    Leave a comment:


  • John Kevin
    replied
    Hello markl,

    You can refer to this forum thread (post#2)
    https://forum.4dsystems.com.au/forum...nd-word-arrays

    In your case, you can set it like this:

    var Array0[24];
    var Array1[24];
    var Data[2];
    var Arrays;

    Data[0]:= Array0;
    Data[1]:= Array1;

    Arrays:=Data[0];

    I hope this is what you are looking for.

    Best Regards,
    Kevin

    Leave a comment:


  • markl
    replied
    Hey, I have a question about arrays. Please tell me the best way to handle this:
    var Array0[24];
    var Array1[24];
    var Data[2] := [Array0[], Array1[]];
    what I am trying to do is access my data in a function using a for loop that will read an eeprom into these arrays so I can print the data.
    The compiler is saying that an Array has to be initialized with a constant value and that I’m missing the semi- colon ??
    Any help would be appreciated.

    thanks,

    Mark

    Leave a comment:


  • papatrexasgre
    replied
    Mark you're the man mate. Thanks a lot. I wasn't *2 on my attempts.
    Last edited by papatrexasgre; 8th August 2016, 08:55 PM.

    Leave a comment:


  • ESPsupport
    replied
    I think you want to do something like this, hopefully the comments will help you understand the 'trick'.

    Code:
    #platform "uLCD-28PTU"
    
    #inherit "4DGL_16bitColours.fnc"
    
    #CONST
        ENGLISH
        GERMAN
        DUTCH
        RUSSIAN
    #END
    
    #DATA
        word jan_eng 0x004A, 0x0041, 0x004E, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word feb_eng 0x0046, 0x0045, 0x0042, 0x0052, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word mar_eng 0x004D, 0x0041, 0x0052, 0x0043, 0x0048, 0
        word apr_eng 0x0041, 0x0050, 0x0052, 0x0049, 0x004C, 0
        word may_eng 0x004D, 0x0041, 0x0059, 0
        word jun_eng 0x004A, 0x0055, 0x004E, 0x0045, 0
        word jul_eng 0x004A, 0x0055, 0x004C, 0x0059, 0
        word aug_eng 0x0041, 0x0055, 0x0047, 0x0055, 0x0053, 0x0054, 0
        word sep_eng 0x0053, 0x0045, 0x0050, 0x0054, 0x0045, 0x004D, 0x0042, 0x0045, 0x0052, 0
        word oct_eng 0x004F, 0x0043, 0x0054, 0x004F, 0x0042, 0x0045, 0x0052, 0
        word nov_eng 0x004E, 0x004F, 0x0056, 0x0045, 0x004D, 0x0042, 0x0045, 0x0052, 0
        word dec_eng 0x0044, 0x0045, 0x0043, 0x0045, 0x004D, 0x0042, 0x0045, 0x0052, 0
    
        word jan_dut 0x004A, 0x0041, 0x004E, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word feb_dut 0x0046, 0x0045, 0x0042, 0x0052, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word mar_dut 0x004D, 0x0041, 0x0041, 0x0052, 0x0054, 0
    
        word jan_ger 0x004b, 0x0041, 0x004E, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word feb_ger 0x0047, 0x0045, 0x0042, 0x0052, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word mar_ger 0x004e, 0x0041, 0x0041, 0x0052, 0x0054, 0
    
        word jan_rus 0x004c, 0x0041, 0x004E, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word feb_rus 0x0048, 0x0045, 0x0042, 0x0052, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word mar_rus 0x004f, 0x0041, 0x0041, 0x0052, 0x0054, 0
    
        word eng jan_eng, feb_eng, mar_eng, apr_eng, may_eng, jun_eng, jul_eng, aug_eng, sep_eng, oct_eng, nov_eng, dec_eng
        word ger jan_ger, feb_ger, mar_ger, apr_eng, may_eng, jun_eng, jul_eng, aug_eng, sep_eng, oct_eng, nov_eng, dec_eng
        word dut jan_dut, feb_dut, mar_dut, apr_eng, may_eng, jun_eng, jul_eng, aug_eng, sep_eng, oct_eng, nov_eng, dec_eng
        word rus jan_rus, feb_rus, mar_rus, apr_eng, may_eng, jun_eng, jul_eng, aug_eng, sep_eng, oct_eng, nov_eng, dec_eng
    
        word mlangs eng, ger, dut, rus
    
    #END
    
    func printUni(var * struni)
        var ch, i ;
        while (ch := struni[i++])
            putch(ch) ;
            i++ ;                   // because the compiler has a byte pointer 'and doesn't know it'.
        wend
    endfunc
    
    func main()
        var i, j, *mlang ;
    //  mlang := mlangs[ENGLISH] ;  // to set lang to english, for example
    
        for (i := 0 ; i < 4; i++)   // for each language
            mlang := mlangs[i] ;
            print("Lang ", i, "\n") ;
            for (j := 0 ; j < 3; j++)   // for a few months
                printUni(mlang[j*2]);   // because the compiler has a byte pointer 'and doesn't know it'.
                print("\n") ;
            next
        next
        repeat                      // maybe replace
        forever                     // this as well
    
    endfunc

    Leave a comment:


  • papatrexasgre
    started a topic Array of arrays of string arrays

    Array of arrays of string arrays

    Hello again. I know it's not a 4D question and that it's more memory allocation and pointer manipulation but.....
    I have this
    Code:
       
        word jan_eng 0x004A, 0x0041, 0x004E, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word feb_eng 0x0046, 0x0045, 0x0042, 0x0052, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word mar_eng 0x004D, 0x0041, 0x0052, 0x0043, 0x0048, 0
        word apr_eng 0x0041, 0x0050, 0x0052, 0x0049, 0x004C, 0
        word may_eng 0x004D, 0x0041, 0x0059, 0
        word jun_eng 0x004A, 0x0055, 0x004E, 0x0045, 0
        word jul_eng 0x004A, 0x0055, 0x004C, 0x0059, 0
        word aug_eng 0x0041, 0x0055, 0x0047, 0x0055, 0x0053, 0x0054, 0
        word sep_eng 0x0053, 0x0045, 0x0050, 0x0054, 0x0045, 0x004D, 0x0042, 0x0045, 0x0052, 0
        word oct_eng 0x004F, 0x0043, 0x0054, 0x004F, 0x0042, 0x0045, 0x0052, 0
        word nov_eng 0x004E, 0x004F, 0x0056, 0x0045, 0x004D, 0x0042, 0x0045, 0x0052, 0
        word dec_eng 0x0044, 0x0045, 0x0043, 0x0045, 0x004D, 0x0042, 0x0045, 0x0052, 0
    
        word jan_dut 0x004A, 0x0041, 0x004E, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word feb_dut 0x0046, 0x0045, 0x0042, 0x0052, 0x0055, 0x0041, 0x0052, 0x0059, 0
        word mar_dut 0x004D, 0x0041, 0x0041, 0x0052, 0x0054, 0
        .  . . . .  you get the picture....
    then I do this:

    Code:
      word january jan_eng, jan_ger, jan_dut, jan_rus
        word february feb_eng, feb_ger, feb_dut, feb_rus
        word march mar_eng, mar_ger, mar_dut, mar_rus
        word april apr_eng, apr_ger, apr_dut, apr_rus
        word may may_eng, may_ger, may_dut, may_rus
        word june jun_eng, jun_ger, jun_dut, jun_rus
        word july jul_eng, jul_ger, jul_dut, jul_rus
        word august aug_eng, aug_ger, aug_dut, aug_rus
        word september sep_eng, sep_ger, sep_dut, sep_rus
        word october oct_eng, oct_ger, oct_dut, oct_rus
        word november nov_eng, nov_ger, nov_dut, nov_rus
        word december dec_eng, dec_ger, dec_dut, dec_rus
    I can then january[0] for English or february[3] for Russian.
    The question is how can I do this:
    months[12] := [january, february, ........]
    And ofcourse how will I access them afterwards? months[11][1]???
    Thank you and sorry if by reading this you want to commit suicide...

Working...
X