Creating Public and Private Functions in VB6

From Free Knowledge Base- The DUCK Project: information for everyone
Revision as of 14:23, 9 January 2008 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, 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))