Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Building an Address by Concatenating Field Values

RSS
Modified on Tue, Jun 22, 2010, 3:47 PM by Administrator Categorized as Algorithms, ·Net Framework
{copytext|div1}
Public Shared Function Address(ByVal name As String, ByVal address1 As String, ByVal address2 As _
String, ByVal address3 As String, ByVal address4 As String, ByVal city As String, ByVal state As _
String, ByVal zipCode As String, ByVal country As String) As String

    Dim result As String = ""
    Dim csz As String = city
    csz = AppendValue(csz, ", ", state)
    csz = AppendValue(csz, " ", zipCode)
    csz = AppendValue(csz, " ", country)

    result = AppendLine(result, name)
    result = AppendLine(result, address1)
    result = AppendLine(result, address2)
    result = AppendLine(result, address3)
    result = AppendLine(result, address4)
    result = AppendLine(result, csz)
    Return result

End Function
'--------------------------------------------------------------------------------------------------
Public Shared Function AppendLine(ByVal input As String, ByVal value As String) As String
    Return AppendValue(input, vbCrLf, value)
End Function
'--------------------------------------------------------------------------------------------------
Public Shared Function AppendValue(ByVal input As String, ByVal delimiter As String, ByVal value _
As String) As String

    Dim result As String = ""
    Dim flag As Integer = 0

    If input.Length <> 0 Then
        flag += 1
    End If

    If value.Length <> 0 Then
        flag += 2
    End If

    Select Case flag
        Case 1
            result = input
        Case 2
            result = value
        Case 3
            result = input & delimiter & value
    End Select

    Return result

End Function

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.