City and State Separation

We have a PAB database that is used by a department here that had been in use since 5.0 (we’re on 6.0.3 now)… When we upgrade to 6x, the database “changed”. If there was no comma between the city and state in 5x, it worked fine (for the reports we printed from it and such) but since there’s no comma between City and state in some of them now, it make everything the city (ie, Chicago IL is in the City field). Any ideas on how to fix this? I have 0 Lotusscript experience but I found this in the Lotus Designer for that database. Can I alter this to show the addresses correctly? Or even put a comma in?

Sub ParseAddress(add As Variant, elements As Variant, whichfield As String)

 REM "Clear out the existing fields so that new/modified address is correct"

If whichfield = "B" Then

	doc.OfficeStreetAddress=""

	doc.OfficeCity=""

	doc.OfficeState=""

End If

If whichfield = "H" Then

	doc.StreetAddress=""

	doc.City=""

	doc.State=""

End If





 REM " The rules to parse an address are as follows:"

 REM " If there is only one word, assume it is the city."

 REM " If there is more than one word and no punctuation, still assume it is the city."

 REM " If there is more than one word and there is a comma, assume left of the comma is city, right is state or province"

 REM " If there are two lines, assume the first line is the address and the second line is the city/state"

 REM " If there are more than two lines, assume the last is city/state, the rest are address"

 REM " Country and ZIP/Postal codes go into different fields."



Punct=Instr(add,",")



If elements(0) = 1 And Punct=0 Then

	If whichfield = "B" Then

		doc.OfficeCity=Trim(add)

		Exit Sub

	End If

	If whichfield = "H" Then

		doc.City=Trim(add)

		Exit Sub

	End If

End If



If elements(0) = 1 And Punct>0 Then

	If whichfield = "B" Then

		doc.OfficeCity=Trim(Left(add,Punct-1))

		doc.OfficeState=Trim(Right(add, Len(add)-Punct))

		Exit Sub

	End If

	If whichfield = "H" Then

		doc.City=Trim(Left(add,Punct-1))

		doc.State=Trim(Right(add, Len(add)-Punct))

		Exit Sub

	End If

End If



If elements(0) > 1 Then

	If whichfield="B" Then

		LastLine=Evaluate(|@Subset(@Explode(BusinessAddress;@Char(13));-1)|,doc)  

		OtherLines=Evaluate(|@Implode(@Subset(@Explode(BusinessAddress;@Char(13));@Elements(@Explode(BusinessAddress;@Char(13)))-1);@NewLine)|,doc)

		doc.OfficeStreetAddress=OtherLines

		Punct=Instr(LastLine(0),",")

		If  Punct >0 Then

			doc.OfficeCity=Trim(Left(LastLine(0),Punct-1))

			doc.OfficeState=Trim(Right(LastLine(0), Len(LastLine(0))-Punct))

		Else

			doc.OfficeCity=Trim(LastLine(0))

		End If

		Exit Sub

	End If

	If whichfield="H" Then

		LastLine=Evaluate(|@Subset(@Explode(HomeAddress;@Char(13));-1)|,doc)

		OtherLines=Evaluate(|@Implode(@Subset(@Explode(HomeAddress;@Char(13));@Elements(@Explode(HomeAddress;@Char(13)))-1);@NewLine)|,doc)

		doc.StreetAddress=OtherLines

		Punct=Instr(LastLine(0),",")

		If  Punct >0 Then

			doc.City=Trim(Left(LastLine(0),Punct-1))

			doc.State=Trim(Right(LastLine(0), Len(LastLine(0))-Punct))

		Else

			doc.City=Trim(LastLine(0))

		End If

		Exit Sub

	End If

End If

End Sub

Subject: City and State Separation

Why not just filter out all data where a comma does not exit and if there are two words, take 2 chars from the left. There may be a small margin of error but easily correctable and manageable for manual entry corrections.

Subject: RE: City and State Separation

First off, again, I have no programming skills for lotus so I have no idea on how to do this. Secondly, some of the city/state combinations may have more than two words (ie, West Lafayette IN)…

Subject: RE: City and State Separation

Are all of the states using the postal abbreviation (that is, can you be sure that the full state name is never used)?

If that’s the case, then StrLeftback and StrRightback are the functions you want to use to separate the string at the final included space. Test first for an included space, then split using the functions mentioned, then test the “tentatively a state” value to see if it’s a two-letter abbreviation.