Array Refrencing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coolcurrent
    New Member
    • Dec 2007
    • 1

    Array Refrencing

    I have an array as below:

    Code:
    .  [B]A   B   C   D   E[/B]
    [B]A[/B]  0   10  20  30  40
    
    [B]B[/B]  10  0   15  20  30
    
    [B]C[/B]  20  15  0   25  30
    
    [B]D[/B]  30  20  25  0   40
    
    [B]E[/B]  40  30  30  40  0
    I also have 2 variables named;

    (1) TOO (to indicate Row)
    (2) FROM (to indicate column)

    I want my variable to be the reference for my array
    e.g if TOO= 1
    FROM=2
    would return 10 (A,B)

    TOO= 3
    FROM=4
    would return 25 (C,D)


    TOO= 3
    FROM=5
    would return 30 (C,E)

    How can I do this please?
    Last edited by Killer42; Dec 28 '07, 07:09 AM. Reason: Added CODE tag to preserve formatting
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Originally posted by coolcurrent
    I want my variable to be the refrence for my array
    e.g if TOO= 1
    FROM=2
    would return 10 (A,B)

    TOO= 3
    FROM=4
    would return 25 (C,D)


    TOO= 3
    FROM=5
    would return 30 (C,E)

    How can I do this Please
    What if you did it like this: TOO = 'C' and FROM = 'D' and you made your array two dimensional? How easy would it be then? All you would have to do is access your array at index [TOO, FROM] and you would have your answer.

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by coolcurrent
      I have an array as below ...
      Your description basically sounds like the definition of a two-dimensional array.

      However, are you saying that you actually have letters "A", etc. for the index values? If so, converting them to numbers is easy enough. There are various techniques you could employ, but probably the simplest is to subtract 64 (or 65) from the ASCII value of the letter. For example, try typing this in VB's immediate window...
      [CODE=vb]PRINT ASC("A") - 64[/CODE]The reason I mentioned 65 is that a number of people prefer to begin arrays at zero rather than one. I don't, but thought I should mention it.

      Comment

      Working...