Visual Basic 6 Programming

Visual Basic was fun. I considered using VB2 for one project, but without database support, it was not the right fit. When VB3 came along with database support, I was in. I lived through the VB4 16/32 bit issues and fought the DLL Hell that was just a part of life back then. When VB6 finally came along and was so solid that the programs actually ran and did what we expected, it was very refreshing. I programmed in Visual Basic for many years.

This is a small example of a function I wrote to be able to log messages that contained binary information. A big part of our programming was serial communications, and the low ASCII chars wreaked havoc on the log files.
I am not offering this as the perfect example of VB6 programming. However, it does show that we had a convention for naming variables and parameters. It also include error handling, which was automatically added and removed from a VB6 Addin I wrote (we called it CodeBuddy).


Public Function wb_ConvertFromBinary(pstrMsg As String) As String
   On Error GoTo ErrorHandler:

   Dim intLoop As Integer
   Dim intLen As Integer
   Dim strReturn As String
   Dim strChar As String
   Dim blnBinary As Boolean
   
   intLen = Len(pstrMsg)
   blnBinary = False
   
   For intLoop = 1 To intLen
   
      strChar = Mid(pstrMsg, intLoop, 1)
      If Asc(strChar) < 32 Then
         blnBinary = True
         strChar = "<" & Right("00" & Asc(strChar), 3) & ">"
      End If
      strReturn = strReturn & strChar
      DoEvents
   Next intLoop

   If blnBinary Then
      strReturn = "BIN:" & strReturn
   End If
   
   wb_ConvertFromBinary = strReturn
   
   Exit Function
ErrorHandler:
   wb_LogError "WBSCommon/wb_ConvertFromBinary", Err.Description, Err.Number, Erl

End Function

Print Friendly, PDF & Email