|
-
Sep 14th, 2000, 04:02 AM
#1
Thread Starter
Member
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
-
Sep 14th, 2000, 09:01 AM
#2
Guru
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. 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!
-
Sep 14th, 2000, 09:18 AM
#3
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|