Normal Topic Postal abbreviations - has anyone done this? (Read 1115 times)
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Postal abbreviations - has anyone done this?
Aug 21st, 2007 at 7:18pm
Print Post Print Post  
Has anyone out there designed a combo box element that presents a lists of U.S. states which, when one is selected, fills the element with the 2-letter postal abbreviation?
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Postal abbreviations - has anyone done this?
Reply #1 - Aug 21st, 2007 at 7:21pm
Print Post Print Post  
Infinity wrote on Aug 21st, 2007 at 7:18pm:
Has anyone out there designed a combo box element that presents a lists of U.S. states which, when one is selected, fills the element with the 2-letter postal abbreviation?

You're probably better off with using @PopupChoiceList and an array for this in 2.0. Holler if you want details/sample code.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Postal abbreviations - has anyone done this?
Reply #2 - Aug 21st, 2007 at 7:43pm
Print Post Print Post  
Quote:
Holler if you want details/sample code.

Yes, please.
  

**
Captain Infinity
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Postal abbreviations - has anyone done this?
Reply #3 - Aug 21st, 2007 at 9:03pm
Print Post Print Post  
Here ya go. Note that the code in GLOBAL CODE is long only because it is filling in the big long table of states and their abbreviations. It actually takes very little code to do the actual work.

GLOBAL CODE
Code
Select All
stat sStates as Array[51, 2] of String
stat sStateList as String

FUNCTION FindState(vState as String) as Int
var vRet as Int
var vCount as Int
var vLoop as Int

	vRet = 0
	vCount = DimLimit(1, sStates)
	vLoop = 1
	While (vLoop <= vCount) And (vRet = 0)
	{
		If sStates[vLoop, 1] = vState
		{
			vRet = vLoop
		}
		vLoop = vLoop + 1
	}
	Return vRet

END FUNCTION

FUNCTION BuildStateList() as String
var vRet as String
var vCount as Int
var vLoop as Int

	vRet = ""
	vCount = DimLimit(1, sStates)
	vLoop = 1
	For vLoop = 1 to vCount
		vRet = vRet + sStates[vLoop, 1] + ";"
	Next
	vRet = @ReplLas(vRet, ";", "")
	Return vRet

END FUNCTION

SUBROUTINE PopulateStatesArray()

	sStates[1, 1] = "ALABAMA"
	sStates[1, 2] = "AL"
	sStates[2, 1] = "ALASKA"
	sStates[2, 2] = "AK"
	sStates[3, 1] = "ARIZONA"
	sStates[3, 2] = "AZ"
	sStates[4, 1] = "ARKANSAS"
	sStates[4, 2] = "AR"
	sStates[5, 1] = "CALIFORNIA"
	sStates[5, 2] = "CA"
	sStates[6, 1] = "COLORADO"
	sStates[6, 2] = "CO"
	sStates[7, 1] = "CONNECTICUT"
	sStates[7, 2] = "CT"
	sStates[8, 1] = "DELAWARE"
	sStates[8, 2] = "DE"
	sStates[9, 1] = "DISTRICT OF COLUMBIA"
	sStates[9, 2] = "DC"
	sStates[10, 1] = "FLORIDA"
	sStates[10, 2] = "FL"
	sStates[11, 1] = "GEORGIA"
	sStates[11, 2] = "GA"
	sStates[12, 1] = "HAWAII"
	sStates[12, 2] = "HI"
	sStates[13, 1] = "IDAHO"
	sStates[13, 2] = "ID"
	sStates[14, 1] = "ILLINOIS"
	sStates[14, 2] = "IL"
	sStates[15, 1] = "INDIANA"
	sStates[15, 2] = "IN"
	sStates[16, 1] = "IOWA"
	sStates[16, 2] = "IA"
	sStates[17, 1] = "KANSAS"
	sStates[17, 2] = "KS"
	sStates[18, 1] = "KENTUCKY"
	sStates[18, 2] = "KY"
	sStates[19, 1] = "LOUISIANA"
	sStates[19, 2] = "LA"
	sStates[20, 1] = "MAINE"
	sStates[20, 2] = "ME"
	sStates[21, 1] = "MARYLAND"
	sStates[21, 2] = "MD"
	sStates[22, 1] = "MASSACHUSETTS"
	sStates[22, 2] = "MA"
	sStates[23, 1] = "MICHIGAN"
	sStates[23, 2] = "MI"
	sStates[24, 1] = "MINNESOTA"
	sStates[24, 2] = "MN"
	sStates[25, 1] = "MISSISSIPPI"
	sStates[25, 2] = "MS"
	sStates[26, 1] = "MISSOURI"
	sStates[26, 2] = "MO"
	sStates[27, 1] = "MONTANA"
	sStates[27, 2] = "MT"
	sStates[28, 1] = "NEBRASKA"
	sStates[28, 2] = "NE"
	sStates[29, 1] = "NEVADA"
	sStates[29, 2] = "NV"
	sStates[30, 1] = "NEW HAMPSHIRE"
	sStates[30, 2] = "NH"
	sStates[31, 1] = "NEW JERSEY"
	sStates[31, 2] = "NJ"
	sStates[32, 1] = "NEW MEXICO"
	sStates[32, 2] = "NM"
	sStates[33, 1] = "NEW YORK"
	sStates[33, 2] = "NY"
	sStates[34, 1] = "NORTH CAROLINA"
	sStates[34, 2] = "NC"
	sStates[35, 1] = "NORTH DAKOTA"
	sStates[35, 2] = "ND"
	sStates[36, 1] = "OHIO"
	sStates[36, 2] = "OH"
	sStates[37, 1] = "OKLAHOMA"
	sStates[37, 2] = "OK"
	sStates[38, 1] = "OREGON"
	sStates[38, 2] = "OR"
	sStates[39, 1] = "PENNSYLVANIA"
	sStates[39, 2] = "PA"
	sStates[40, 1] = "RHODE ISLAND"
	sStates[40, 2] = "RI"
	sStates[41, 1] = "SOUTH CAROLINA"
	sStates[41, 2] = "SC"
	sStates[42, 1] = "SOUTH DAKOTA"
	sStates[42, 2] = "SD"
	sStates[43, 1] = "TENNESSEE"
	sStates[43, 2] = "TN"
	sStates[44, 1] = "TEXAS"
	sStates[44, 2] = "TX"
	sStates[45, 1] = "UTAH"
	sStates[45, 2] = "UT"
	sStates[46, 1] = "VERMONT"
	sStates[46, 2] = "VT"
	sStates[47, 1] = "VIRGINIA"
	sStates[47, 2] = "VA"
	sStates[48, 1] = "WASHINGTON"
	sStates[48, 2] = "WA"
	sStates[49, 1] = "WEST VIRGINIA"
	sStates[49, 2] = "WV"
	sStates[50, 1] = "WISCONSIN"
	sStates[50, 2] = "WI"
	sStates[51, 1] = "WYOMING"
	sStates[51, 2] = "WY"

END SUBROUTINE

	PopulateStatesArray()
	sStateList = BuildStateList() 



ANY OTHER EVENT
Code
Select All
var vPos as Int
var vChoice as String
var vAbbrev as String

	vChoice = @PopupChoiceList(sStateList, "SELECT A STATE")
	If vChoice <> ""
	{
		vPos = FindState(vChoice)
		If vPos > 0
		{
			vAbbrev = sStates[vPos, 2]
			@MsgBox("The abbreviation for " + vChoice + " is " + vAbbrev, "", "")
		}
		Else
		{
			@MsgBox("No abbreviation for " + vChoice, "", "")
		}
	} 


     

  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Infinity
Senior Member
Members
*****
Offline


Diagonally parked in a
parallel dimension

Posts: 1290
Location: Massachusetts
Joined: May 27th, 2005
Re: Postal abbreviations - has anyone done this?
Reply #4 - Aug 24th, 2007 at 1:59pm
Print Post Print Post  
Sorry for the late reply but WOW!  Thanks Erika, that's fantastic.
  

**
Captain Infinity
Back to top
IP Logged