-
is there a way in VB to programatically go through all the passed parameters of a function in a similar way that C uses the argc and argv vectors ?
Also I want to know if there is an API call that can obtain the current routine that VB is in.
What I want to achive is a comma deilimited string that contains all the parameters so that I can do some app debugging. Ie. something like this.....
private sub MySub(p1 as string, p2 as integer, p3 as long)
dim sParams as string
dim i as integer
dim sSubName as string
sSubName=AN_API_TO_GET_THE_CURRENT_SUB_NAME
for i=1 to argc
sParams=sParams & argv(i) ", "
next i
' sParams contains "String Val, 10, 132213, "
MyDebugRoutine ("Entered " & sSubName & " with " & sParams)
.. rest of sub
end sub
-
Going through the passed parameters...
Check out the ParamArray keyword.
Best example I can think of is an Average function.
Here it is:
Code:
Function Average(ParamArray AnyNumberOfArguments() As Variant) As Single
Dim I As Integer
For I = LBound(AnyNumberOfArguments) To UBound(AnyNumberOfArguments)
Average = Average + AnyNumberOfArguments(I)
Next
' The formula for how many members are in an array, is:
' UBound - LBound + 1
' We have to divide by this (this is Average, not Sum)
Average = Average / (UBound(AnyNumberOfArguments) - LBound(AnyNumberOfArguments) + 1)
End Function
Read the help documents about ParamArray for more information.
Getting the current procedure name: Nope. You'll get over it. :rolleyes: Why do you need it, anyway? It can definitely be solved otherwise.
For debugging:
Code:
Debug.Print "Debug information goes here"
That information goes into the Immediate window. If you can't see that window, hit Ctrl+G and it will appear.
Debug.Print lines are ignored when you compile your EXE.
Hope this was helpful! :)
-
yeah, there's no api for that, you can pause your app of course and it will show the code, the exact line where it is stopped.
But if you want, you could have a global variable, then in each function, sub or property make the first line
thatglobalvariable="thatfunction name"
You know what i mean?
And then you can access thatglobalvariable anytime, showing which procedure is running...
I just don't recommend this method to debug, but that was a runtime solution