Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

function as argument

  Asked By: Cory    Date: Feb 24    Category: MS Office    Views: 1003
  

Does anyone know if it is possible to have a function as an argument
to another function in VBA? If so, can you provide an example?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Mae Roberts     Answered On: Feb 24

Yes. Done it been there etc. Some applications... most notably
MAPPER from Sperry - a popular mainframe app, have a problem when
things refer to themselves... like Int = Int + 1, where a 3rd
intermediary is necesery.

VB/A/S Has no problems there. *All* versions of basic to my knowledge
have been incestuous.. that is been able to refer to themselves.

The function  will be resolved before passing the parameter to the
function/sub.

 
Answer #2    Answered By: Freda Lane     Answered On: Feb 24

I've never even thought about it. A function  returns a value. I have
used the results of a function as an argument  to another function
though.

Psuedo Code:

Sub test() 'Start Here with Pressing F8
GetString ("Hello-World")
End Sub

Public Function GetString(strString As String) As String
StripChars2 (strString)
End Function

Public Function StripChars2(strText As String) As String
strTestString = strText
strStripChars = " ()-"
For i = 1 To Len(strStripChars)
strBadChar = Mid(strStripChars, i, 1)
strTestString = Replace(strTestString, strBadChar, vbNullString)
Next
Debug.Print strTestString

End Function

 
Answer #3    Answered By: Hooriya Khan     Answered On: Feb 24

Yes you can nest functions in VBA.
The following example  controls the formatting of dates.
As you can see the Now function  (which returns the system date and
time) is used as the first argument  to the Format function, whose
second argument is the format picture.


Sub FunctionWithinFunction()
' Use Ctrl + G to display the Immediate window before
' running this procedure.

Debug.Print Format(Now, "dd-mmmm-YYYY")

End Sub

 
Didn't find what you were looking for? Find more on function as argument Or get search suggestion and latest updates.




Tagged: