by SCC (9 Submissions)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Mon 10th May 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Format a Postcode...... 4 3 format
API Declarations
Function FormatPostcode(myOriginalPostcode As String)
'Need Some Code? Request it at www.SmokeCrack.co.uk
Dim myCount As Integer
myCount = 0
Do
myCount = myCount + 1
If InStr(1, myOriginalPostcode, " ") <> 0 Then
myOriginalPostcode = Left(myOriginalPostcode, InStr(myOriginalPostcode, " ") - 1) & Mid(myOriginalPostcode, InStr(1, myOriginalPostcode, " ") + 1, 100)
End If
Loop Until InStr(1, myOriginalPostcode, " ") = 0
'START CHECKING LENGTH OF POSTCODE
If Len(myOriginalPostcode) = 7 Then
myOriginalPostcode = Left(myOriginalPostcode, 4) & " " & Right(myOriginalPostcode, 3)
End If
If Len(myOriginalPostcode) = 6 Then
If IsNumeric(Mid(myOriginalPostcode, 2, 1)) = True Then
'B 40 0DP
myOriginalPostcode = Left(myOriginalPostcode, 1) & " " & Mid(myOriginalPostcode, 2, 2) & " " & Right(myOriginalPostcode, 3)
Else:
'BN 4 0DP
myOriginalPostcode = Left(myOriginalPostcode, 2) & " " & Mid(myOriginalPostcode, 3, 1) & " " & Right(myOriginalPostcode, 3)
End If
End If
'Need Some Code??? Request it at www.SmokeCrack.co.uk
Msgbox FormatPostcode("BN89PO")
'Will return BN 8 9PO
End Sub