|
-
Nov 14th, 2010, 06:00 AM
#1
Thread Starter
Junior Member
Function variable to be seperate for each call....
Hi,
Lets say i have:
Private Function TestFunction (byval VariableA as SomeClass)
Static VariableB as integer
VariableB = variableA.position
Return Nothing
End Function
I then do:
For i = 1 to 100
TestFunction(InputA)
Next
So i used static so variableB still has value from previous loop.
This is no problems, but if i want to do
For i = 1 to 100
TestFunction(InputA)
TestFunction(InputB)
TestFunction(InputC)
Next
It uses the same VariableB to get .position from InputA, InputB and InputC so at the end of the loop, it is VariableB = InputC.
How can i make it use a seperate VariableB for each function call?
So at end of loop,
Function call 1 has VariableB = inputA.position
Function call 2 has VariableB = inputB.position
Function call 2 has VariableB = inputC.position
So how can i make each TestFunctionB line seperate from the others?
Um.. I am not sure if i make any sense but I am in a hurry right now. If it needs to be explained clearer please reply and I try make more sense.
-
Nov 14th, 2010, 06:06 AM
#2
Re: Function variable to be seperate for each call....
You can't have your cake and eat it too. If you have one function then you have one Static variable. A single variable can't have three different values. If you want multiple values then you need multiple variables, so you need multiple functions.
-
Nov 14th, 2010, 06:35 AM
#3
Thread Starter
Junior Member
Re: Function variable to be seperate for each call....
Ok then,
I guess I have to change my code.
Thanks for the reply
-
Nov 14th, 2010, 07:24 AM
#4
Re: Function variable to be seperate for each call....
Code:
Public Function TestFunctionA (byval VariableA as SomeClass)
Static VariableB as integer
Return TestFunction(VariableA, VariableB)
End Function
Public Function TestFunctionB (byval VariableA as SomeClass)
Static VariableB as integer
Return TestFunction(VariableA, VariableB)
End Function
Public Function TestFunctionC (byval VariableA as SomeClass)
Static VariableB as integer
Return TestFunction(VariableA, VariableB)
End Function
Private Function TestFunction (byval VariableA as SomeClass, ByRef VariableB as integer)
'function body goes here
VariableB = variableA.position
Return Nothing
End Function
Code:
For i = 1 to 100
TestFunctionA(InputA)
TestFunctionB(InputB)
TestFunctionC(InputC)
Next
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
|