Total Visual SourceBook

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office 2007 and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

Separate version for Access/Office 2003, 2002, and 2000.

Separate version for:
Access 97/95


View all FMS products for Microsoft AccessAll Our Microsoft Access Products

SourceBook Info:

Why SourceBook?

 

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

 

 

 

Microsoft Access, Office/VBA, VB6 Modules royalty-free source code libraryMicrosoft Access Modules royalty-free source code libraryMicrosoft Access VBA and VB6 Module Library Free trial of Total Visual SourceBook for Microsoft Access, Office, VB6 and VBA

Class: Bitly in Category Internet/Web : Internet/Web from Total Visual SourceBook

Use the Bit.ly web service to convert a long Internet URL string to a short one and vice versa with VBA and VB6.

Bit.ly is used by Twitter to shorten URLs in tweets. For your own use, a single Bit.ly access token can be used for OAuth authentication. This is free from: https://bitly.com/a/oauth_apps. To support other users, a Bit.ly user name and API Key is required. This is free from: https://bitly.com/a/your_api_key.

Procedure List

Procedure Name

Type

Description

(Declarations) Declarations Declarations and private variables for the CBitly class
AccessToken Property Bit.ly Access token which is for personal use of Bit.ly API calls
UserName Property Bit.ly user name for multiple account use of Bit.ly API calls
ApiKey Property Bit.ly API Key multiple account use of Bit.ly API calls
Class_Initialize Initialize Initialize values to defaults which may be overridden with property settings and methods
GetCredentials Private Create the syntax to provide the credentials to the Bit.ly API call Credentials can be provided as an Access Token or User Name and API Key
ShortenURL Method Create a shortened URL using the Bit.ly URL shortening service
OriginalURL Method Convert a shortened Bit.ly URL to its original long URL.
InfoXML Method Get information for a page from a shortened Bit.ly URL. The result is in XML which can be parsed using the CXMLRead class.
URLEncode Private Encodes a string so it can be passed to a URL
TrimResponse Private Process response to terminate at the first return character. If there isn't one, the entire string is returned.

Example Code for Using Class: Bitly

' Examples of using the CBitly class to use the Bit.ly web service to convert a long Internet URL string to a short one and vice versa with VBA and VB6.
' To use Bit.ly API calls, you need to create an Bit.ly account (free) and get the OAuth authentication access token or user name and API key.
' See the declarations section of the CBitly class for additional details.
'
' To use this example, create a new module and paste this code into it.
' Then run the procedure by putting the cursor in the procedure and pressing:
'    F5 to run it, or
'    F8 to step through it line-by-line (see the Debug menu for more options)

' Set these login values once you get them from bit.ly
Private Const mcstrAccessToken As String = ""
Private Const mcstrUserName As String = ""
Private Const mcstrAPIKey As String = ""

' Set the default URL to convert
Private Const mcstrLongURL As String = "http://www.fmsinc.com/MicrosoftAccess/SourceCodeLibrary.html"

Private Sub Example_CBitly()
  ' Commments: Examples of using the CBitly class to use the Bit.ly web service to convert a long Internet URL string to a short one and vice versa.

  Dim fOK As Boolean
  Dim clsBitly As CBitly
  Dim strLongURL As String
  Dim strBitlyURL As String
  Dim strOriginal As String
  Dim strInfoXML As String

  Set clsBitly = New CBitly

  ' Set login properties. Either the AccessToken alone or the user name/API Key combination is used.
  fOK = True
  If mcstrAccessToken <> "" Then
    clsBitly.AccessToken = mcstrAccessToken
  ElseIf (mcstrUserName <> "") And (mcstrAPIKey <> "") Then
    clsBitly.UserName = mcstrUserName
    clsBitly.ApiKey = mcstrAPIKey
  Else
    MsgBox "Set the Bit.ly login information in the Declarations section before running this code."
    fOK = False
  End If

  If fOK Then
    ' Prompt the user for a URL to shorten
    strLongURL = InputBox("Specify the URL to convert to Bit.ly", "CBitly Example", mcstrLongURL)

    If strLongURL <> "" Then
      ' Get the shortened URL from Bit.ly
      strBitlyURL = clsBitly.ShortenURL(strLongURL)
      If strBitlyURL <> "" Then
        Call InputBox(strLongURL & " converted to ", "BitlyURL Example", strBitlyURL)

        ' Show how to convert the Bit.ly shortened URL back to its original URL
        strOriginal = clsBitly.OriginalURL(strBitlyURL)
        If strOriginal = "" Then
          MsgBox "Shortened Bit.ly URL " & strBitlyURL & "cannot be converted back to its original URL. This is most likely because it wasn't saved to your account whent the bit.ly was created."
        Else
          MsgBox "Converted the shortened Bit.ly URL from " & strBitlyURL & " back to " & strOriginal
        End If

        strInfoXML = clsBitly.InfoXML(strBitlyURL)
        Debug.Print "Information on the URL in XML format:"
        Debug.Print strInfoXML
      End If
    End If
  End If

  ' Clean up
  Set clsBitly = Nothing
End Sub

Microsoft Access Module LibraryOverview of Total Visual SourceBook

The source code in Total Visual SourceBook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Additional Resources