PDA

View Full Version : Code function



justdriving
10-15-2011, 06:37 AM
Hi, I need help from somebody to explain me Step-by-Step what this VBA code is doing?

Please mark a comment after every step.

Someone will answer to search HELP in VBE at Right top box.





Dim DirSep As String
Dim LibPath As String
Dim AnalysisPath As String
Dim WorkbookName As String

Dim FunctionIDs(130, 0 To 1)

Private Function GetMacroRegId(FuncText As String) As String
Debug.Print ("[GetMacroRegId] '" & FuncText & "' <")
For i = LBound(FunctionIDs) To UBound(FunctionIDs)
If (LCase(FunctionIDs(i, 0)) = LCase(FuncText)) Then
If (Not (IsError(FunctionIDs(i, 1)))) Then
GetMacroRegId = FunctionIDs(i, 1)
Debug.Print ("[GetMacroRegId] '" & FuncText & "' -> '" & GetMacroRegId & "' >")
Exit Function
End If
End If
Next i
Debug.Print ("[GetMacroRegId] Error while finding '" & FuncText & "' >")
End Function

Function Bin2Hex(number As Variant, Optional places As Variant) As Variant
Bin2Hex = Application.Run(GetMacroRegId("BIN2HEX"), number, places)
End Function

Kenneth Hobs
10-15-2011, 07:45 AM
Step through the code with F8 if you don't know and hover over variables. Or, open the Locals Window and debug through the code with F8. That is what debug if for.

You might try commenting where you get code as that has not code that runs unless used as a UDF. Debug.print for UDFs is one what to see what is going on with a UDF. I do that as standard practice to give credit where credit is due. It also helps me point people to code rather than reposting it.

justdriving
10-15-2011, 02:29 PM
Thanks Ken. Please excuse, if I was wrong. Yet, I am looking to learn in this forum. Is this not right place? I am requesting your advice, not questioning you.

Aflatoon
10-17-2011, 12:43 AM
It seems to me that Ken gave you advice. It is far better for you to learn to debug code as Ken suggested, otherwise you will have to ask every time you come across a new piece of code.

justdriving
10-17-2011, 02:33 PM
I was just trying to take some learning opportunity through this forum. Someone may help me. Many people have learnt many things through this forum.

Aflatoon
10-17-2011, 02:45 PM
I fear you are missing the point - you are being given a learning opportunity. Learning to debug code is an extremely valuable skill; far more useful than simply being told what a specific line of code does.