Announcement

Collapse
No announcement yet.

Question for Gary Beene

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

  • Question for Gary Beene

    Hey Gary
    I was able to use your code and manipulate it a bit so I could see and have a better understanding about this ARRAY SCAN. I think your program helped me to answer my own question about a starting index for two dimensional arrays. I picture a two dimensional array as a database with rows and columns. We ALWAYS know what column we want to search to find a variable we just don't know what row it is in. I was under the impression that if you had 10 columns and wanted to search the 9th column you could have your index start at column 8 or even 9, but the help file clearly states that the index starts AT THAT ELEMENT IN THE ARRAY meaning in the previous sentence it would start at the 8th or 9th element depending on my setting. I found that this was absolutely NOT THE WAY TO DO IT. What I found is if you start your index with 1 and the second number being the column you want to search like array(1,8) then search for UBOUND(array(1)) equals your search variable then it works everytime. AM I RIGHT ABOUT THIS OR NOT. Try the code below and let me know if I am right or wrong. This would only be for 2 dimensional arrays I don't know about any others.


    Code:
    	
    	
    	
    
    
    Code:
    'Compilable Example:
    FUNCTION PBMAIN() AS LONG
       LOCAL iRow,iCol,iPos AS LONG, mVar$,numRecs&,mCol&,RC$,mrow&,colNum&
    LOCAL hWin AS DWORD
    'D(cols,     rows)
    REDIM D(1 TO 6, 1 TO 6) AS STRING
    D(1,1)="1"
    D(2,1)="2"
    D(3,1)="3"
    D(4,1)="XX"
    D(5,1)="5"
    D(6,1)="6"
    D(1,2)="7"
    D(2,2)="8"
    D(3,2)="XX"
    D(4,2)="10"
    D(5,2)="11"
    D(6,2)="12"
    D(1,3)="13"
    D(2,3)="14"
    D(3,3)="15"
    D(4,3)="16"
    D(5,3)="17"
    D(6,3)="18"
    D(1,4)="19"
    D(2,4)="20"
    D(3,4)="21"
    D(4,4)="22"
    D(5,4)="23"
    D(6,4)="24"
    D(1,5)="25"
    D(2,5)="XX"
    D(3,5)="27"
    D(4,5)="28"
    D(5,5)="29"
    D(6,5)="30"
    D(1,6)="XX"
    D(2,6)="32"
    D(3,6)="33"
    D(4,6)="34"
    D(5,6)="35"
    D(6,6)="36"
    mRow& = 20 : mCol& = 50
    GRAPHIC WINDOW TEXT "",650,80,25,80 TO hwin
    GRAPHIC ATTACH hWin,0
    GRAPHIC SET POS(mCol&,mRow&)
    GRAPHIC PRINT "Row/Col_1      Col_2      Col_3      Col_4      Col_5      Col_6"
    mRow& = mRow& + 20
       mCol& = mCol& + 40
    FOR iRow = LBOUND(d(1)) TO UBOUND(d(1))
    FOR iCol = LBOUND(d(2)) TO UBOUND(d(2))
    RC$ = FORMAT$(VAL(d(iRow,iCol)),"00")
    IF RC$ = "00" THEN RC$ = "XX"
    GRAPHIC SET POS(mCol&,mRow&)
    GRAPHIC PRINT RC$
               mCol& = mCol& + 65
    NEXT iCol
           mCol& = 90
           mRow& = mRow& + 30
    NEXT iRow
    WHILE colNum& < 1 OR colNum& > 6
    GRAPHIC SET POS(60,240)
    GRAPHIC INPUT "Enter the column number to search for XX from (1 to 6) ", colNum&
    ITERATE
       WEND
    
    mVar$ = "XX"
    numRecs& = UBOUND(d(1))
    ARRAY SCAN D(1,colNum&) FOR numRecs&, = mVar$, TO iPos
    IF iPos > 0 THEN
           ? "Row = "+STR$(iPos)+" Column = "+STR$(colNum&)+$CRLF+ _
    "Array("+STR$(iPos)+","+STR$(colNum&)+")"  'location relative to the starting point
    ELSE
           ? "XX was not found in column "+STR$(colNum&)
    END IF
       GRAPHIC WINDOW END hWin
    END FUNCTION  
Working...
X