Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Parsing a Street Address into Separate Fields
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01144790
Message ID:
01144841
Views:
17
Here is some code from that old application:
	local lStNum, lStNumExt, lStreet, lcLotCode, lUnit
				store 0 to lStNum
				store space(1) to lStNumExt, lStreet, lcLotCode, lUnit
				tmpStreet = upper(alltrim(Bldmstr.PStreet))
				if " C/O " $ (" " + m.tmpStreet) or " ATTN: "  $ (" " + m.tmpStreet)
&& This means, that name was accidentally converted to street, don't parse it
				else
					tmpStreet = .CleanUpStreet(m.tmpStreet)
					tmpStreet = reduce(m.tmpStreet)
*--------------------------------------------------------------------------
* -- updated:rmm:07/27/00
* --	first get the unit number, then rest of the address
*--------------------------------------------------------------------------
					lUnit = alltrim(.ParseUnit(m.tmpStreet+" ",@tmpStreet,@lcLotCode))
					lStNum = .ParseStNum(@m.tmpStreet)
					lStNumExt = alltrim(.ParseStNumExt(@m.tmpStreet,m.lStNum))
					lStreet=proper(alltrim(m.tmpStreet))
					if m.tlProgramExists and !empty(Bldmstr.StateUse)
						lcLotCode = LotCodeCalc(Bldmstr.StateUse, m.lStNum, m.lStreet)
					endif
					replace Bldmstr.StNum with m.lStNum, ;
						Bldmstr.StNumExt with m.lStNumExt, ;
						Bldmstr.Street with m.lStreet, ;
						Bldmstr.LotCode with m.lcLotCode, ;
						Bldmstr.Unit with m.lUnit
				endif
*--------------------------------------------------------------------------
* --  Parsing Street Number from the variable passed
*--------------------------------------------------------------------------
lparameter tcPStreet
local RetVal, lcStNum, lnI, lcNum, lcChar, lContinue
RetVal = 0			&& Return Value
* -- Looking for the First Space & everything before it
&& Updated:NN: 06/19/02
lcStNum = substr(m.tcPStreet,1,at(" ",m.tcPStreet)-1)
lcNum=''
lContinue = .t.
lnI = 0
do while m.lContinue 
    lnI = m.lnI+1
    if m.lnI>len(m.lcStNum) or m.lnI > 7 && 9999999 - assume it's a max possible St Num
       lContinue = .f.
    else   
	    lcChar = substr(m.lcStNum,m.lnI,1)
	    if not isdigit(m.lcChar)
	       lContinue = .f.
	    else
	       lcNum = m.lcNum + m.lcChar
	    endif
	endif
enddo

if not empty(m.lcNum)
   RetVal = val(m.lcNum)
endif   	            
*!*	do case
*!*	case at("-",m.lcWord2) > 0		&& Value before the hyphene
*!*		RetVal = val(substr(m.lcWord2,1,at("-",m.lcWord2)-1))
*!*	case at("/",m.lcWord2) > 0		&& Value before the dash
*!*		RetVal = val(substr(m.lcWord2,1,at("/",m.lcWord2)-1))
*!*	case val(m.lcWord2) > 0			&& Street Number itself
*!*		RetVal = val(m.lcWord2)
*!*	otherwise						&& No street number found
*!*		RetVal = 0
*!*	endcase
return m.RetVal
There are bunch of other methods. Luckily I have all functionality in one class. I can send you the class code by e-mail, if you want.
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform