Announcement

Collapse
No announcement yet.

Help Using an array

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

  • Help Using an array

    I have a table I would like to split out.
    Example: 11/15/2008 725
    11/16/2008 154
    11/17/2008 503
    I would like to spred the numbers 725,154,503 into 10 array slots, each having 0 1 2 3 4 5 6 7 8 9
    725 x X X
    154 X X X
    503 X X X
    Once I have them spred I want to print the array

    Can anyone tell me how to do this?

  • #2
    Originally posted by Lloyd Plantholt View Post
    I have a table I would like to split out.
    Example: 11/15/2008 725
    11/16/2008 154
    11/17/2008 503
    I would like to spred the numbers 725,154,503 into 10 array slots, each having 0 1 2 3 4 5 6 7 8 9
    725 x X X
    154 X X X
    503 X X X
    Once I have them spred I want to print the array

    Can anyone tell me how to do this?
    Lloyd, we all love a challenge here. But I think you need to provide a little more info. Perhaps show a full line or two of what the output should look like. ie
    725 x 0134689
    154 x 0236789
    503 x 1246789
    Is that what you mean? It's unclear what you want.

    ================================
    Volcanoes, I never go there.
    Don't care if I see Pele'S hair,
    For I am the sort
    Who enjoys the sport
    Of sitting in my easy chair.
    Chris Papa
    ================================
    It's a pretty day. I hope you enjoy it.

    Gösta

    JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
    LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

    Comment


    • #3
      Originally posted by Lloyd Plantholt View Post
      I have a table I would like to split out.
      Example: 11/15/2008 725
      11/16/2008 154
      11/17/2008 503
      I would like to spred the numbers 725,154,503 into 10 array slots, each having 0 1 2 3 4 5 6 7 8 9
      725 x X X
      154 X X X
      503 X X X

      The array elements are numbered 0 thru 9
      I want to take the first example and spred it out under the elements corresponding to their value as shown by the x's then record # 2 and record #3 the same way, then print
      the output should look like this:
      date array 0 1 2 3 4 5 6 7 8 9
      xx/xx/xx 2 5 7
      xx/xx/xx 1 4 5
      xx/xx/xx 0 3 5
      Once I have them spred I want to print the array


      Can anyone tell me how to do this?
      a
      a
      a
      Last edited by Lloyd Plantholt; 18 Nov 2008, 01:20 PM.

      Comment


      • #4
        I'm with Gösta on this. Even with the extra information, I have no idea what you want to do.

        Perhaps if you were to explain the context it would help.

        Comment


        • #5
          If I understand what you want to do properly, then this is roughly how I would proceed:

          Code:
          DIM ElementCheck(0 TO 9) AS STATIC LONG
          LOCAL i AS LONG, tString  AS STRING
          
          'Input a line into a string, ie. 11/16/2008 154
          FOR i = 1 TO NumberOfInputItems
          'Code to input items
          'Sample:
            tString = "11/16/2008 154 "
            CALL ExtractDigits(tString, ElementCheck()
          NEXT i
          ' Sample output
          FOR i = 0 TO 9
            DoMyPrinting ElementCheck(i) ' Output technique dependant on program.
          NEXT i
          
          FUNCTION ExtractDigits(tString AS STRING, ElementCheck() AS LONG) AS LONG
            LOCAL inString  AS STRING, _
                  xString  AS STRING, _
                  tPos     AS LONG, _
                  noDigits AS LONG, _
                  ndx      AS LONG
          
            inString = RTRIM$(tString) ' remove trailing spaces.
          
          'extract the last digits, by searching for the first blank space preceding your number.
            tPos = INSTR(-1, inString, " ") ' position of white space
            xString = MID$(inString, tPos+1) ' extract the desired string into a substring.
            noDigits = LEN(xString) ' Find the number of digits in the substring.
            IF noDigits > 0 THEN ' If we have a number, then process it.
              FOR ndx = 1 TO noDigits  ' Check each element of the substring
                tValue = VAL(MID$(xString, ndx, 1) ' find the numeric equivalent of the digit
                ElementCheck(tValue) = ElementCheck(tValue) + 1 ' increment the corresponding array element.
              NEXT ndx
              FUNCTION = noDigits ' returns number of digits processed.
            ELSE
              FUNCTION = -1 ' flag for no digits found
            END IF
          END FUNCTION
          regards, Ian
          :) IRC :)

          Comment


          • #6
            Lloyd, this method uses 1 thru 9 of the 10 array elements available to do it.
            Code:
            #COMPILE EXE
            #DIM ALL
            
            FUNCTION PBMAIN () AS LONG
               
               LOCAL ii, x AS LONG, printStr AS STRING
               DIM table(3) AS STRING
               DIM spreadArr(9) AS STRING
               
               table(1) = "11/15/2008 725"
               table(2) = "11/16/2008 154"
               table(3) = "11/17/2008 503"
                                                                             
               FOR ii = 1 TO 9
                  x = (ii - 1) \ 3 + 1                                                   'choose table element
                  spreadArr(ii) = MID$(table(x), LEN(table(x)) - (2 - (ii + 2) MOD 3), 1)'get last three digits into spreadArr()
                  printStr = printStr & spreadArr(ii) & " "                              'write to print string
                  IF ii MOD 3 = 0 THEN printStr = printStr & $CRLF                       'add carriage return every three digits
               NEXT
               
               ? printStr
            
            END FUNCTION

            Comment


            • #7
              Using an Array to spred outout

              OK, Lets try this one again:
              I have a list of dates and values example xx/xx/xxxx 725
              I want to spred the 725 into an array consisting of 0 1 2 3 4 5 6 7 8 9
              spred like this x x x
              there are approx 31 enteries in the list
              Can anyone tell me how to do this????

              Comment


              • #8
                The problem is, you are saying you want "725" spread out into "0 1 2 3 4 5 6 7 8 9" and showing it appearing as "X X X " ... I for one can't figure out what you want.

                Show a couple of inputs with desired outputs.. eg
                I want '725' to appear as "bbbbbbbb725" where "b" = space
                or
                I want '1234' to appear as "bxxxxbbbbb" where 'x' = '1' and 'b'=space

                Something like that.
                Michael Mattias
                Tal Systems (retired)
                Port Washington WI USA
                [email protected]
                http://www.talsystems.com

                Comment


                • #9
                  Or Maybe like this?
                  Code:
                  date array  0 1 2 3 4 5 6 7 8 9
                   xx/xx/xx       2     5   7      ' == 725
                   xx/xx/xx     1     4 5          ' == 154
                   xx/xx/xx   0     3   5          ' == 503
                  Rgds, Dave

                  Comment


                  • #10
                    You're not just trying to right=justify "725" for display are you?

                    This....
                    Code:
                      Z$ = RSET$(String_Var, desired_size)
                    ... might be a little more straightforward than setting up an array of decimal digits.
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment


                    • #11
                      Or something like this:
                      Code:
                      LOCAL THEARRAY(),xx,yy,num AS LONG
                      DIM THEARRAY(20081201 TO 20081231,0 TO 9)
                      This will give you an array with 31 by 10 elements
                      The first subscript is the date, the second is the placement of each digit.
                      Code:
                      FOR xx=20081201 to 20081231
                      num=???????
                        THEARRAY(XX,0)=getfirtdigit(num)
                        THEARRAY(xx,1)=getseconddigit(num)
                        THEARRAY(XX,2)=getthirddigit(num)   'The balance of the elements(THEARRAY(xx,3) to THEARRAY(xx,9)) are set to 0
                      NEXT xx
                      This is pseudo stuff just to see if I'm heading off into the wrong direction so it needs work.
                      Last edited by Rodney Hicks; 23 Nov 2008, 02:07 PM.
                      Rod
                      I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                      Comment


                      • #12
                        Originally posted by Lloyd Plantholt View Post
                        OK, Lets try this one again:
                        I have a list of dates and values example xx/xx/xxxx 725
                        I want to spred the 725 into an array consisting of 0 1 2 3 4 5 6 7 8 9
                        spred like this x x x
                        there are approx 31 enteries in the list
                        Can anyone tell me how to do this????
                        Llyod,

                        It would seem that your statement "spred like this" is not a description that is supplying sufficient information for anyone to come up with a solution. I'm afraid you won't be getting any "how to" until you give a better "what".

                        We're all guessing here, and we're all trying to come up with ways that would satisfy what we're guessing you want. But as you can see, there are many possible interpretations to what you've given. For example, I'm wondering if you're looking for TOTALs of how many 5's have been found?

                        Please "try again" to explain, either in words or in a series of diagrams, precisely what you would like to see each of your several samples come out looking like.

                        I think we're all understanding that there is to be a set of columns:
                        0 1 2 3 4 5 6 7 8 9

                        but can you show us what would appear below them if 725, 154, and 503 were "spread out"?


                        Thanks,
                        -John

                        Comment


                        • #13
                          I think Lloyd wants: xyz ==> (x, y, z)

                          ie a one-dimensional array consisting of 100s, 10s and 1s

                          Scratch that: I missed 10 array slots
                          Last edited by David Roberts; 23 Nov 2008, 03:57 PM.

                          Comment


                          • #14
                            I was interrupted during my first post so I'll redo it.
                            Code:
                            LOCAL THEARRAY(),xx,yy,num AS LONG
                            DIM THEARRAY(20081201 TO 20081231,0 TO 9)
                            This will give you an array with 31 by 10 elements
                            The first subscript is the date, the second is the placement of each digit.
                            Code:
                            FOR xx=20081201 to 20081231
                              num=???????
                              THEARRAY(XX,0)=getfirtdigit(num)
                              THEARRAY(xx,1)=getseconddigit(num)
                              THEARRAY(XX,2)=getthirddigit(num)   'The balance of the elements(THEARRAY(xx,3) to THEARRAY(xx,9)) are set to 0
                            NEXT xx
                            For clarity(hopefully) this would create an array looking something like this:
                            Code:
                            The 8 digit number is the first subscript
                              v
                              v
                                      0  1  2  3  4  5  6  7  8  9    <<<<these are the second subscript
                            20081201  7  2  5  0  0  0  0  0  0  0   
                            20081202  1  5  4  0  0  0  0  0  0  0 
                            20081203  6  3  9  0  0  0  0  0  0  0   
                            20081204  0  0  0  0  0  0  0  0  0  0   
                            20081205  0  0  0  0  0  0  0  0  0  0   
                            20081206  0  0  0  0  0  0  0  0  0  0 
                            .
                            .
                            .
                            20081230  0  0  0  0  0  0  0  0  0  0   
                            20081231  0  0  0  0  0  0  0  0  0  0
                            or do you want them in the proper column like so:
                            Code:
                                      0  1  2  3  4  5  6  7  8  9    
                            20081201  0  0  2  0  0  5  0  7  0  0   
                            20081202  0  1  0  0  4  5  0  0  0  0 
                            20081203  0  0  0  3  0  0  6  0  0  9  
                            20081204  0  0  0  0  0  0  0  0  0  0   
                            20081205  0  0  0  0  0  0  0  0  0  0   
                            20081206  0  0  0  0  0  0  0  0  0  0 
                            .
                            .
                            .
                            20081230  0  0  0  0  0  0  0  0  0  0   
                            20081231  0  0  0  0  0  0  0  0  0  0
                            or some other fashion?
                            Rod
                            I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                            Comment


                            • #15
                              What's wrong with this program?????

                              $compile exe
                              ' Name of Program LOTBAS.BAS
                              ' Date of Program 11/10/2008
                              ' Function SPRED NUMBERS
                              dim ary(10)


                              open "lotbase.txt" for input as #1
                              open "lotout.txt" for output as #2

                              do while not eof(1)
                              line input #1, dta$

                              dte$ = (mid$(dta$,1,10))
                              nr1 = val(mid$(dta$,12,1))
                              nr2 = val(mid$(dta$,16,1))
                              nr3 = val(mid$(dta$,20,1))

                              ary,nr1 = nr1 <
                              ary,nr2 = nr2 <----- this does not work
                              ary,nr3 = nr3 <

                              print #2, dte$;" ";ary

                              loop

                              Comment


                              • #16
                                It doesn't compile, that's what's wrong with it.

                                Comment


                                • #17
                                  ary,nr1 = nr1 <
                                  ary,nr2 = nr2 <----- this does not work
                                  ary,nr3 = nr3 <
                                  ==>
                                  Code:
                                  ary(nr1) = nr1
                                  ary(nr2) = nr3
                                  ary(nr3) = nr3
                                  See also: http://www.powerbasic.com/support/pb....php?do=bbcode

                                  Using code tags makes it MUCH easier to read on-line.
                                  Michael Mattias
                                  Tal Systems (retired)
                                  Port Washington WI USA
                                  [email protected]
                                  http://www.talsystems.com

                                  Comment


                                  • #18
                                    Not sure which compiler you are using. The following was done in PBWin 9.0.

                                    Code:
                                    #COMPILE EXE
                                    #DIM ALL
                                    
                                    FUNCTION PBMAIN () AS LONG
                                      LOCAL ary(),nr1,nr2,nr3,temp,cntr AS LONG
                                      LOCAL dteS, dtaS AS STRING    'removed the type specifier and replaced it with S to indicate string
                                      DIM ary(1 TO 3)
                                    
                                    
                                      OPEN "lotbase.txt" FOR INPUT AS #1
                                      OPEN "lotout.txt" FOR OUTPUT AS #2
                                    
                                      DO WHILE NOT EOF(1)
                                        INCR cntr
                                        LINE INPUT #1, dtaS
                                    
                                        dteS = (MID$(dtaS,1,10))
                                        nr1 = VAL(MID$(dtaS,12,1))   '
                                        nr2 = VAL(MID$(dtaS,16,1))
                                        nr3 = VAL(MID$(dtaS,20,1))
                                    
                                        ary(1) = nr1 '<
                                        ary(2) = nr2 '<----- this should work
                                        ary(3) = nr3 '<
                                    
                                        PRINT #2, dteS;" ";ary(1)," ",ary(2)," ",ary(3)    'I don't really think this is what you want so comment it out and uncomment
                                        'temp=(ary(1)*100)+(ary(2)*10)+ary(3)              'these two lines
                                        'PRINT #2, dteS;" ";temp
                                        
                                      LOOP
                                      CLOSE #1
                                      CLOSE #2
                                    END FUNCTION
                                    This does not spread the numbers out in any fashion, but it does gather them to what you were doing as best I could figure out from your last post.
                                    Rod
                                    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                    Comment


                                    • #19
                                      I'm sorta gettin the feelin Lloyd is playing with us, boys.

                                      =====================================================
                                      The random nature of quantum physics
                                      means that there is always a minuscule, but nonzero,
                                      chance of anything occurring,
                                      including that the new collider could spit out
                                      man-eating dragons.
                                      NY Times article on the Large Hadron Collioder
                                      =====================================================
                                      It's a pretty day. I hope you enjoy it.

                                      Gösta

                                      JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                                      LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                                      Comment


                                      • #20
                                        >I'm sorta gettin the feelin Lloyd is playing with us, boys

                                        I don't get that, and I'm hardly on the short list for the Nobel Prize in Sensitivity.

                                        Looking at last code (the one with the compile error).....

                                        Is ary() supposed to be a frequency table? ie, ary(8) is the number of occurences of '8' in the input file?

                                        (Note to self for list of Top Ten Things You Need to be an Effective Programmer: "ability to clearly express in plain English the desired output and logic of your program.")

                                        MCM
                                        Michael Mattias
                                        Tal Systems (retired)
                                        Port Washington WI USA
                                        [email protected]
                                        http://www.talsystems.com

                                        Comment

                                        Working...
                                        X