Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Bordering States Function

Status
Not open for further replies.

MrMeric

Technical User
Apr 1, 2004
48
US
Does anyone know if there exists a function that will determine if a state is a neighbor/bordering state?

For example, a user would pass in two states and the function would determine if they are neighbors: BorderingState(StateOne, StateTwo).

Examples:
BorderingState(WI,IL) would return True.
BorderingState(WA,FL) would return False.

If this function does not exist, I'd be happy to create it if I could get some suggestions as to how to make it.
 
Got it... I'm not sure the bordering states are 100% correct, but it works. It's pretty quick, too.

Code:
Public Function BorderingState(strState1 As String, strState2 As String) As Boolean
    Dim vStates               As Variant
    Dim i                     As Integer
    vStates = Array("AK-", _
                    "AL-MS,TN,GA,FL", "AR-OK,MO,TX,LA,MS,TN", "AZ-CA,NV,UT,CO,NM", _
                    "CA-NV,AZ,OR", "CO-WY,NE,KS,OK,NM,AZ,UT", "CT-", "DE-MD", _
                    "FL-GA,AL", "GA-AL,SC,FL,TN,NC", "HI-", "IA-MN,WI,IL,MO,NE,SD", _
                    "ID-WA,MT,WY,UT,NV,OR", "IL-WI,IN,KY,MO,IA", "IN-MI,IL,KY,OH", _
                    "KS-NE,MO,OK,CO", "KY-IL,IN,OH,WV,VA,TN", "LA-TX,AR,MS", _
                    "MA-NH,RI,VT,NY", "MD-DE,DC", "ME-NH", "MI-OH,IN", "MN-ND,WI,IA,SD", _
                    "MO-IA,IL,KY,TN,AR,OK,KY,NE", "MS-LA,AR,TN,AL", "MT-ND,SD,WY,ID", _
                    "NC-VA,TN,SC", "ND-MT,MN,SD", "NE-SD,IA,MO,KS,CO,WY", "NH-VT,MA,ME", _
                    "NJ-PA", "NM-AZ,UT,CO,OK,TX", "NV-OR,ID,UT,AZ,CA", "NY-VT,MA,PA,NJ", _
                    "OH-MI,IN,KY,WV,PA", "OK-KY,MO,AR,TX,NM", "OR-WA,ID,NV,CA", "PA-NY,NJ,DE,OH,WV,DC", _
                    "RI-MA", "SC-NC,GA", "SD-ND,MN,IA,NE,WY,MT", "TN-KY,VA,NC,GA,AL,MS,AR,MO", _
                    "TX-NM,OK,AR,LA", "UT-NV,ID,WY,CO,NM,AZ", "VA-DC,WV,KY,TN,NC", "VT-NH,NY,MA", _
                    "WA-OR,ID", "WI-MN,IA,IL,MI", "WV-OH,PA,DC,VA,KY", "WY-MT,SD,NE,CO,UT,ID")


    For i = LBound(vStates) To UBound(vStates)
        If (Left(vStates(i), 2) = strState1) Then
            If InStr(1, vStates(i), strState2) Then
                BorderingState = True
            Else
                BorderingState = False
            End If
        End If
    Next
    
    Erase vStates

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top