Module: AsciiBinaryHex in Category General VBA/VB6 : Data Type and Unit Conversion from Total Visual SourceBook

Convert ASCII characters, numbers, and hexadecimal values, encode URL characters and generate HTML colors using VBA and VB6.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the modAsciiBinaryHex module.
OctalStringToDecimal Procedure Converts the passed string representation of an octal number to a decimal long integer.
RGBToHTMLColor Procedure Formats an RGB value into the hex format standard used in HTML. HTML color tags require that the color be specified in a hex RGB format. This function turns a VBA/VB6 RGB value (red, green, blue).
URLEncode Procedure Encode a string so it can be passed to a URL by converting some ASCII characters to HEX values with an option to handle spaces.
BinaryStringToHexString Procedure Converts a string representation of a binary number to a string representation of a hexadecimal number.
NumberToHex Procedure Convert a numeric value to a hex value (commonly used to convert ASCII values to Hex codes in web URLs).
NumberToCharacter Procedure Convert a numeric value to an ASCII character.
CharacterToHex Procedure Convert a character value to a hex value (commonly used to convert ASCII values to Hex codes in web URLs).
CharacterToNumber Procedure Convert a character value to a numeric value.
HexToCharacter Procedure Convert a hexadecimal value to an ASCII character (useful for translating characters in web URLs).
HexToBinary Procedure Converts a string representation of a hex number to a string representation of a binary number.
ConvertLongToBinaryString Procedure Converts a long number to a string representation of a binary number.
' Example of modAsciiBinaryHex
'
' 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)

Private Sub Example_modAsciiBinaryHex()
  ' Comments: Examples of using the modAsciiBinaryHex module to convert data bewteen ASCII characters, numbers, and hex values; encode URL characters and generate HTML colors using VBA and VB6.
  '           See the results in the Immediate Window.

  Dim intCounter As Integer

  Debug.Print "Hex value of 00000101 is " & BinaryStringToHexString("00000101")
  Debug.Print "Octal value of 108 returns: " & OctalStringToDecimal(108)

  Debug.Print "Binary value of &H1000 is " & HexToBinary("&H1000")

  Debug.Print "ConvertLongToBinaryString(): "
  For intCounter = 10000 To 10010
    Debug.Print "  " & intCounter & " : " & ConvertLongToBinaryString(intCounter, 15)
  Next intCounter

  Debug.Print
  Debug.Print "Hex Functions for different characters (Character, Number, Hex, NumberToHex, HexToCharacter"
  Debug.Print ":", CharacterToNumber(":"), CharacterToHex(":"), NumberToHex(58), HexToCharacter("3A")
  Debug.Print "#", CharacterToNumber("#"), CharacterToHex("#"), NumberToHex(35), HexToCharacter("23")
  Debug.Print "A", CharacterToNumber("A"), CharacterToHex("A"), NumberToHex(65), HexToCharacter("41")
  Debug.Print "a", CharacterToNumber("a"), CharacterToHex("a"), NumberToHex(97), HexToCharacter("61")
  Debug.Print "Z", CharacterToNumber("Z"), CharacterToHex("Z"), NumberToHex(90), HexToCharacter("5A")
  Debug.Print "z", CharacterToNumber("z"), CharacterToHex("z"), NumberToHex(122), HexToCharacter("7A")

  Debug.Print
  Debug.Print "ASCII Table (Number, Character, Hex)"
  For intCounter = 32 To 100
    Debug.Print intCounter, NumberToCharacter(intCounter), NumberToHex(intCounter)
  Next intCounter

  Debug.Print
  Debug.Print "Convert search string for web URL address: " & URLEncode("Microsoft & Access")     ' Displays Microsoft%20%26%20Access
  Debug.Print "RGBToHTMLColor value of 255 is " & RGBToHTMLColor(255)                             ' Displays FF0000

End Sub

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.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

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 and VB6

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


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"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

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS