Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Array lookup
Message
From
19/01/2006 04:14:12
 
General information
Forum:
Visual FoxPro
Category:
FoxWeb
Title:
Environment versions
Visual FoxPro:
VFP 9
Miscellaneous
Thread ID:
01088253
Message ID:
01088293
Views:
7
>Simple array question. I have an array with 4 columns and an unknown number of rows. The first column is lname, second column is fname, third column is mname, and the fourth is ssn. I want to find the row that matches l_lname, l_fname and l_mname and extract the ssn and the row number.
>
>thanks
>
>brenda

Interesting issue.
a few minutes and a nice code has gone out,
also for the one that has some doubt on ASCAN.
CLEAR
RAND(1) && repeatable

DIMENSION aInfo[1000000,4]
FOR K=1 TO ALEN(aInfo)
  aInfo[K]=INT(RAND()*10000)
NEXT


matchRow = INT(RAND()*ALEN(aInfo,1))+1

t1=SECONDS()

cSearchCount=3

DIMENSION colSearch[m.cSearchCount]
colSearch[1] = 1
colSearch[2] = 2
colSearch[3] = 3

dimension colSearchInfo[m.cSearchCount]
colSearchInfo[1]=aInfo[m.matchRow ,colSearch[1]]
colSearchInfo[2]=aInfo[m.matchRow ,colSearch[2]]
colSearchInfo[3]=aInfo[m.matchRow ,colSearch[3]]

rFound	= 1
cRoll	= 0

SET TEXTMERGE TO "output_test$.txt" NOSHOW ON

FOR c=0 to m.cSearchCount - 1
  \ Search on ROW =<<STR(m.rFound)>>	Column = <<colSearch[1 + (m.c + m.cRoll) % m.cSearchCount]>>
  
  rcFound=ASCAN(m.aInfo;
         ,colSearchInfo[colSearch[1 + (m.c + m.cRoll) % m.cSearchCount]],m.rFound;
         ,-1;
         ,colSearch[1 + (m.c + m.cRoll) % m.cSearchCount];
         ,8)
  \\	Next Row = <<m.rcFound>>
  IF m.rcFound > m.rFound
	 rFound = m.rcFound
	 cRoll  = m.c
	 c	= 0
	 LOOP
  ENDIF
  IF EMPTY(m.rcFound)
  	  rFound = 0
      EXIT
  ENDIF
NEXT
\ ----------------------------------------------------------------------
\ SEARCH ROW = <<m.matchRow>> ON <<ALEN(aInfo,1)>>
\ TIME = <<SECONDS()-t1>> ROW FOUND = <<m.rFound>> INFO FOUND = <<IIF(empty(m.rFound),"not found",aInfo[m.rFound,4])>>
SET TEXTMERGE TO
MODIFY FILE "output_test$.txt"
ERASE "output_test$.txt"
Previous
Reply
Map
View

Click here to load this message in the networking platform