Results 1 to 15 of 15
  1. #1
    Join Date
    Jan 2008
    Posts
    54

    Unanswered: 2 dimensional array problem

    I have a 2 dimensional array consisting of dates and numbers from 1 to 6

    Date 1 2 3 4 5 6
    02/01/2012 x x x
    05/01/2012 x x x
    10/01/2012 x x x
    14/01/2012 x x x
    26/01/2012 x x x

    I have numbers 2 and 4 and I like these 2 numbers though all those dates above one row a time from the top date 02/01/2012 through 26/01/2012 and find whether that row has either 2 or 4, I will consider that row is valid.

    The end result should be
    02/01/2012
    10/01/2012
    26/01/2012

    I would like Ms Access do it programmatically. Can someone please help?

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    sorry
    maybe me being thick this morning but I haven't got a clue what you are trying to do
    I'd rather be riding on the Tiger 800 or the Norton

  3. #3
    Join Date
    Jan 2008
    Posts
    54
    The array should be
    Date 1 2 3 4 5 6
    02//01/2012 x x x
    05/01/2012 x x x
    10/01/2012 x x x
    14/01/2012 x x x
    26/01/2012 x x x


    Given two numbers 2 and 4, I want to see that which row has either 2 or 4. If that row has either number 2 or 4, that row is accepted as valid. From the array, the result should be row 1,3 and 5 because row 1,3 and 5 has either number 2 or number 4.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    nope still not getting it
    I don't understand from your sample data how you determine rows 1,3 & 5 are selected

    when you say array do you mean an array or do you mean rows in a table?
    it may help if you post sample data but enclose if using the code tags.. look for the # symbol above or used [ c o d e ] & [ /c o d e ] without the spaces
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Jun 2011
    Location
    Inside your mind
    Posts
    297
    I understand what you're saying, but the sample data you're providing, with just x's doesn't demonstrate it very well.

    Are you trying to say that the x's could be any number, and if they are a 2 or a 4 then they should be accepted.

    So:

    Code:
        Date   1 2 3 4 5 6
    02/01/2012 x x x	
    05/01/2012 x x x	
    10/01/2012 x x x
    14/01/2012 x x x
    26/01/2012 x x x
    But your data actually looks like:

    Code:
        Date   1 2 3 4 5 6
    02/01/2012 2 4 1
    05/01/2012 6 8 3
    10/01/2012 1 2 5
    14/01/2012 3 3 3
    26/01/2012 4 1 1
    Is that a better representation of your data?

    I also don't understand why you're using:

    Code:
    Date 1 2 3 4 5 6
    Multi-dimensional arrays aren't tables, and shouldn't be given headings.
    Looking for the perfect beer...

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    we don't know if its an array or data from a table

    it would be very easy in a table
    Code:
    select my,column,list from mytable
    where column1 in (2,4)
    or column2 in (2,4)
    or column3 in (2,4)
    or column4 in (2,4)
    or column5 in (2,4)
    or column6 in (2,4)
    order by some,column,list
    if it is an array then
    Code:
    dim ArrayPointer as integer
    dim ColumnID as integer
    for ArrayPointer = 0 to NoItemsInaArray 'NoItemsInArray will need to be defiend or set elsewhere or use a property which tells you the number of items int he array
      for ColumnID = 1 to 6
        if myarray(ArrayPointer,columnid) = 2 or myarray(ArrayPointer,columnid) = 2 then
          'do somethign here
        else
          'do nothing here
        endif
      next ColumnID
    next ArrayPointer
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Jun 2011
    Location
    Inside your mind
    Posts
    297
    Think you meant:

    Code:
    if myarray(ArrayPointer,columnid) = 2 or myarray(ArrayPointer,columnid) = 4 then
    There... But I'm still not totally sure this is what they're even looking for.
    Looking for the perfect beer...

  8. #8
    Join Date
    Jan 2008
    Posts
    54
    Sorry I have difficulty of formatting the array here, unlike MS word. The symbol x is to check the row and column as true. If an x is placed in row 02/01/2012 and under number 1 it means that row 02/01/2012 contains number 1 and so on.

    1,2,3,4 ,5 and 6 are the number headings. For example row 02/01/2012 has an x below 1, 2 and 5, it means that on the row 02/01/2012 contains only number 1, number 2 and number 5 only. Given that I have number 2 and 4, this row 02/01/2012 is valid as it contains a number 2.

    Row 05/01/2012 may have number 1, number 3 and number 6. This is indicated by x below 1,3 and 6. So if I am given number 2 and 4, then Row 05/01/2012 would not be valid as this row 05/01/2012 does not contain either number 2 or 4.

    I hope this is not confusing.

  9. #9
    Join Date
    Jun 2011
    Location
    Inside your mind
    Posts
    297
    With you now... So you're talking about something that looks like:

    Code:
        Date   1 2 3 4 5 6
    02/01/2012 x x     x	
    05/01/2012 x   x     x
    10/01/2012 x x     x x
    14/01/2012 x   x x x x
    26/01/2012 x         x
    Then if there's an x for 2, or for 4, then you want to process those dates in some way shape or form?

    So in the example I just gave, you're interested in:

    02/01/2012
    10/01/2012
    14/01/2012

    Yeah?


    If that's the case, why would you use a multi-dimensional array? You're using MS Access, which uses database tables. It would be a lot simpler, and more effective to simply use a table for this.

    The example Healdem provided you with can easily be adapted to produce what you want. For example:

    Code:
    dim ArrayPointer as integer
    dim ColumnID as integer
    for ArrayPointer = 0 to NoItemsInaArray 'NoItemsInArray will need to be defiend or set elsewhere or use a property which tells you the number of items int he array
      for ColumnID = 1 to 6
        if (ColumnID = 2) or (ColumnID = 4) then 'Check the two columns you're interested in, in this case, 2 & 4...
          if (myarray(ArrayPointer,columnid) = "x") then 'Check to see if either of those columns contain an "x"...
            MsgBox "Accepted Date is: " & myarray(ArrayPointer, 0) 'If they do, output the date in a MsgBox. - You'll want to change this to whatever you want it to do with the date.
          end if
        else
          'do nothing here.
        end if
      next ColumnID
    next ArrayPointer
    Untested, but it should work *touches wood*.
    Last edited by kez1304; 06-14-12 at 10:50.
    Looking for the perfect beer...

  10. #10
    Join Date
    Jan 2008
    Posts
    54
    Kez1304, wow that's precisely what I wanted. Thank you for your help. Btw how did format the array? Using attached image file?

  11. #11
    Join Date
    Oct 2009
    Location
    221B Baker St.
    Posts
    486
    Btw how did format the array? Using attached image file?
    If i understand the question, no this was done using the "Code" tag (which is the # symbol next to the "quote" tag. Part of the data "Coded" is:

    Code:
        Date   1 2 3 4 5 6
    02/01/2012 x x     x	
    05/01/2012 x   x     x
    For this example i only used part of the data .

  12. #12
    Join Date
    Jan 2008
    Posts
    54
    Sorry. You mean before I type x at that position I must type # before x.

  13. #13
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    NO
    as suggested in post#4
    either use the [ c o d e ] & [ / c o d e ] tags (minus the spaces) or use the 'go advanced' button when replying and select the # icon
    I'd rather be riding on the Tiger 800 or the Norton

  14. #14
    Join Date
    Jun 2011
    Location
    Inside your mind
    Posts
    297
    Code:
    This makes the font a monospace type, much like courier is in Word.
      i  m  e  th   o t   mo  s a   t  e,
    The above looks like:

    [ CODE ]
    This makes the font a monospace type, much like courier is in Word.
    i m e th o t mo s a t e,
    [ /CODE ]

    But without any spaces between the symbols [ and ]... But as you can see, the spaces are lost when it isn't using the code tag.

    Glad the code worked for you.
    Looking for the perfect beer...

  15. #15
    Join Date
    Jan 2008
    Posts
    54
    Healdem, Kez1304 and Papadi. Thank you guys for being patience and helpful.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •