Solved

VB Binary Error Messages

Posted on 2002-07-09
2
145 Views
Last Modified: 2010-05-02
I am working with an API for a 3rd party program.

This program has several error codes as follows

1 - Error Description 1
2 - Error Description 2
4 - Error Description 4
8 - Error Description 8
16 - Error Description 16
32 - Error Description 32
64 - Error Description 64

When this API returns an error though it only returns 1 error code.  It adds the error numbers together so if an eror code of 6 is returned you know that this is made up of error 4 and error 2 as this is the only combination that gives 6.  Similarly if an erro code of 9 is retured you know this must have been an error code of 8 and 1.

What I need is a VB function, code etc which will parse any given binary number to give me a list or array etc of the individual error numbers which make up a returned error.

I could write this myself but I'm in a hurry so rather than general ideas on how I might write this I just want quick and easy copy and paste code.

Thanks

Dave
0
Comment
Question by:daveamour
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 7140266

Private Function GetError(ByVal intError As Integer) As String
    Dim intValue As Integer
    Dim intPower As Integer
    intValue = intError
    For intPower = 6 To 0 Step -1
        If intValue >= 2 ^ intPower Then
            GetError = GetError & "Description " & CStr(2 ^ (intPower)) & vbLf
            intValue = intValue - (2 ^ intPower)
        End If
    Next
End Function

Call :

Msgbox GetError(6)


       
0
 
LVL 19

Author Comment

by:daveamour
ID: 7140269
I've actually already solved this.  There are more than 7 error though.

I converted the error message to a binary string and then wrote this code:

Private Function showXMLErrors(strErrorNumber As String) As String
    Dim i As Integer
    Dim strXML As String
   
    strXML = "<?xml version=""1.0"" encoding=""UTF-8"" ?>"
    strXML = strXML & "<Errors>"
   
    For i = 1 To Len(strErrorNumber)
      strXML = strXML & "<Error Code=" & 2 ^ (Len(strErrorNumber) - i) & ">" & Mid(strErrorNumber, i, 1) & "</Error>"
    Next
   
    strXML = strXML & "</Errors>"
   
    showXMLErrors = strXML
End Function

Thanks anyway though and you can have the points for helping.

Cheers

Dave
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vba find the last empty column 10 88
Help in WHSCRIPT 9 47
VBA error replacing data 6 37
Visual Studio 2005 text editor 10 35
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now