Loading ...
Sorry, an error occurred while loading the content.

Arrays of undefined size

Expand Messages
  • Jean-François Colas
    Hello List, Sorry, probably another point I m afraid I misunderstand a few. If I plan to use an array about which I don t know the number of elements... Do I
    Message 1 of 5 , Dec 21, 2011
    • 0 Attachment
      Hello List,

      Sorry, probably another point I'm afraid I misunderstand a few.

      If I plan to use an array about which I don't know the number of
      elements... Do I have another way than reserving one with as many places
      I expect in it, such as something like that:
      ^!SetArray %MyArray%=;;;;;;;;;;;;;;;;;;;;;;;;;;

      If not, and if I expect about one hundred of elements, Do I have a way
      to construct a string with a pattern repeating a nunmber of times, other
      than a loop? In other words, do I need all the code below to create a
      single rather huge array?

      ^!Set %AString%=""
      ^!Set i=0
      :ALoop
      ^!Set %AString%=^%Astring%;
      ^!Inc %i%
      ^!If ^%I% < 100 ALoop
      ^!Setarray %MyArray%=^%AString%
      ^!Info Number of elements of MyArray: ^%Myarray0%. MyArray = ^%MyArray%.
      :end

      Thanks,
      J.-F.
    • Dan Gagne
      J.-F. Build the array using the ^!Append command. Just prefix (or suffix) each cell data with the delimiter string. Then declare the array later Dan Gagne
      Message 2 of 5 , Dec 21, 2011
      • 0 Attachment
        J.-F.
        Build the array using the ^!Append command. Just prefix (or suffix) each cell
        data with the delimiter string. Then declare the array later

        Dan Gagne




        ________________________________
        From: Jean-François Colas <jfcolas@...>
        To: ntb-clips@yahoogroups.com
        Sent: Wed, December 21, 2011 2:14:14 PM
        Subject: [Clip] Arrays of undefined size


        Hello List,

        Sorry, probably another point I'm afraid I misunderstand a few.

        If I plan to use an array about which I don't know the number of
        elements... Do I have another way than reserving one with as many places
        I expect in it, such as something like that:
        ^!SetArray %MyArray%=;;;;;;;;;;;;;;;;;;;;;;;;;;

        If not, and if I expect about one hundred of elements, Do I have a way
        to construct a string with a pattern repeating a nunmber of times, other
        than a loop? In other words, do I need all the code below to create a
        single rather huge array?

        ^!Set %AString%=""
        ^!Set i=0
        :ALoop
        ^!Set %AString%=^%Astring%;
        ^!Inc %i%
        ^!If ^%I% < 100 ALoop
        ^!Setarray %MyArray%=^%AString%
        ^!Info Number of elements of MyArray: ^%Myarray0%. MyArray = ^%MyArray%.
        :end

        Thanks,
        J.-F.



        [Non-text portions of this message have been removed]
      • flo.gehrke
        ... You could create an array containing 100 free variables with... ^!SetArray %MyArray%=^$StrFill( ; ;99)$ ^!Info [L]MyArray: ^%MyArray%^PSize: ^%MyArray0%
        Message 3 of 5 , Dec 21, 2011
        • 0 Attachment
          --- In ntb-clips@yahoogroups.com, Jean-François Colas <jfcolas@...> wrote:
          >
          > If I plan to use an array about which I don't know the number of
          > elements... Do I have another way than reserving one with as many
          > places I expect in it, such as something like that:
          > ^!SetArray %MyArray%=;;;;;;;;;;;;;;;;;;;;;;;;;;

          You could create an array containing 100 free variables with...

          ^!SetArray %MyArray%=^$StrFill(";";99)$
          ^!Info [L]MyArray: ^%MyArray%^PSize: ^%MyArray0%

          But what's the use of that? You are free to enlarge or to reduce an array, or to assign a new value to particular variables. Try this...

          ; Create array %MyArray% and assign three values
          ^!SetArray %MyArray%=A;B;C
          ^!Info [L]New array: ^%MyArray%^PSize: ^%MyArray0% entries
          ; Enlarge array adding three more values
          ^!SetArray %MyArray%=^%MyArray%;D;E;F
          ^!Info [L]Enlarged array: ^%MyArray%^PSize: ^%MyArray0% entries
          ; Change single contents
          ^!Set %MyArray6%=X
          ^!Info [L]Changing value #6: ^%MyArray%^PSize: ^%MyArray0% entries
          ; Reduce array to 4 values
          ^!Set %MyArray0%=4
          ^!Info [L]Reduced array: ^%MyArray%^PSize: ^%MyArray0% entries
          ; Remove array from memory
          ^!SetArray %MyArray%=""

          Regards,
          Flo
        • Ian NTnerd
          ... Arrays are dynamic. They can be added to any time. Some programming language require you to declare a variable before using it. NoteTab does not require
          Message 4 of 5 , Dec 21, 2011
          • 0 Attachment
            On 22/12/2011 8:14 AM, Jean-François Colas wrote:
            >
            > Hello List,
            >
            > Sorry, probably another point I'm afraid I misunderstand a few.
            >
            > If I plan to use an array about which I don't know the number of
            > elements... Do I have another way than reserving one with as many places
            > I expect in it, such as something like that:
            > ^!SetArray %MyArray%=;;;;;;;;;;;;;;;;;;;;;;;;;;
            >
            > If not, and if I expect about one hundred of elements, Do I have a way
            > to construct a string with a pattern repeating a nunmber of times, other
            > than a loop? In other words, do I need all the code below to create a
            > single rather huge array?
            >
            Arrays are dynamic. They can be added to any time. Some programming
            language require you to declare a variable before using it. NoteTab does
            not require this.

            Just create it when you need it.
            Many of my arrays look lie this.
            ^!SetListDelimiter ^p
            ^!setarray %line%=^$getfiletext("^%projectpath%fields.txt")$

            The first line changes the list delimiter from ; to a carriage return.
            The second line gets the list for the array from a text file. It may be
            hundreds or thousands of lines long.

            Often I create a second array for each line, one line at a time.
            ^!SetListDelimiter ^t
            ^!setarray %field%=^%line^%index%%

            This parses a line with tab characters separating fields.

            In my experience NoteTab does handle arrays okay. The processing may be
            slow to loop through tens of thousands of records.

            You find the last array number by the variable name with a zero at the
            end ^%line0%

            If you need more array elements then just add more
            ^!setarray %newarray%=^%oldarray%;newvalue

            I think you are worrying when you don't need to.

            Ian
            >
            >
            > ^!Set %AString%=""
            > ^!Set i=0
            > :ALoop
            > ^!Set %AString%=^%Astring%;
            > ^!Inc %i%
            > ^!If ^%I% < 100 ALoop
            > ^!Setarray %MyArray%=^%AString%
            > ^!Info Number of elements of MyArray: ^%Myarray0%. MyArray = ^%MyArray%.
            > :end
            >
            > Thanks,
            > J.-F.
            >
            >



            [Non-text portions of this message have been removed]
          • Sezor
            Thanks Flo for a useful summary Sezor
            Message 5 of 5 , Dec 22, 2011
            • 0 Attachment
              Thanks Flo for a useful summary
              Sezor


              flo.gehrke wrote:
              > --- In ntb-clips@yahoogroups.com, Jean-François Colas <jfcolas@...> wrote:
              >> If I plan to use an array about which I don't know the number of
              >> elements... Do I have another way than reserving one with as many
              >> places I expect in it, such as something like that:
              >> ^!SetArray %MyArray%=;;;;;;;;;;;;;;;;;;;;;;;;;;
              >
              > You could create an array containing 100 free variables with...
              >
              > ^!SetArray %MyArray%=^$StrFill(";";99)$
              > ^!Info [L]MyArray: ^%MyArray%^PSize: ^%MyArray0%
              >
              > But what's the use of that? You are free to enlarge or to reduce an array, or to assign a new value to particular variables. Try this...
              >
              > ; Create array %MyArray% and assign three values
              > ^!SetArray %MyArray%=A;B;C
              > ^!Info [L]New array: ^%MyArray%^PSize: ^%MyArray0% entries
              > ; Enlarge array adding three more values
              > ^!SetArray %MyArray%=^%MyArray%;D;E;F
              > ^!Info [L]Enlarged array: ^%MyArray%^PSize: ^%MyArray0% entries
              > ; Change single contents
              > ^!Set %MyArray6%=X
              > ^!Info [L]Changing value #6: ^%MyArray%^PSize: ^%MyArray0% entries
              > ; Reduce array to 4 values
              > ^!Set %MyArray0%=4
              > ^!Info [L]Reduced array: ^%MyArray%^PSize: ^%MyArray0% entries
              > ; Remove array from memory
              > ^!SetArray %MyArray%=""
              >
              > Regards,
              > Flo
              >
              >
              >
              > ------------------------------------
              >
              > Fookes Software: http://www.fookes.com/
              > NoteTab website: http://www.notetab.com/
              > NoteTab Discussion Lists: http://www.notetab.com/groups.php
              >
              > ***
              > Yahoo! Groups Links
              >
              >
              >
              >
            Your message has been successfully submitted and would be delivered to recipients shortly.