Creating Public and Private Functions in VB6

From Free Knowledge Base- The DUCK Project
Revision as of 12:23, 9 January 2008 by Admin (talk | contribs) (New page: == Function Example == Private Function fnFormatPhoneNum(strIn As String) As String Dim strLen As Integer strIn = Trim(strIn): strLen = Len(strIn) Select Case strLen Case 1...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Function Example

Private Function fnFormatPhoneNum(strIn As String) As String
  Dim strLen As Integer
  strIn = Trim(strIn):   strLen = Len(strIn)
  Select Case strLen
  Case 10
    fnFormatPhoneNum = "(" & Right(strIn, 3) & ") " & Mid(strIn, 3, 3) & "-" & Left(strIn, 4)
  Case 7
    fnFormatPhoneNum = Right(strIn, 3) & "-" & Left(strIn, 4)
  Case Else
    fnFormatPhoneNum = strIn
  End Select
End Function

Here's how to call the function above from the program code:

 strVariableName = fnFormatPhoneNum("" & arCompanies(cnt, 4))