• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 664
  • Last Modified:

CALLBYNAME examples?

I need some examples of how you might use CallByName to for instance setup a variable to execute a variety of procedures and pass them different values based on what a user decides to make more reusable code.  Anyone want to try this in VB6?
  • 3
  • 2
1 Solution
Advanced_TechAuthor Commented:
I'd rather not get hate emails from future people who spend points to read your answer redirecting them to another answer.  Paste the answer here or dont submit an answer.  Obviously if you know thats the answer you have been there and paid the pointsd already so why make others also waste points to get to the same text?
Advanced_TechAuthor Commented:
This gets even better the Answer you refer me to refers everyone to yet another one!  


I love this!  Anyone else enjoying this as much as I am?

EE Staff needs to make posting redirections policy as officially unacceptable I think!
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


well ,

take or leave it

i am trying to help , i am not get to be a millionare from your Q.

Advanced_TechAuthor Commented:
True!  I doubt Expert Points will threaten to become the currency of choice for any major economies in the immediate future.  

Still any QUESTION asking for examples (ie sample code) should not simply result in redirection to another similar question which then again redirects us to yet another question.  Thats ludicrous and sets a precedent for the eventual uselessness of this entire system.  

EE Admins please delete this question as it appears nobody has any interest in trying to actually work with exploring this new VB function with us.
1. Start a new Standard EXE project in Visual Basic. Form1 is created by


2. Add a Class Module (Class1) to the project.
3. Add the following code to the Class Module:

      Option Explicit
      Private MyPropValue As Integer

      Public Function Multiply(x As Integer, y As Integer) As Integer
         Multiply = x * y
      End Function

      Public Property Get MyProperty() As Variant
         MyProperty = MyPropValue
      End Property

      Public Property Let MyProperty(ByVal vNewValue As Variant)
         MyPropValue = vNewValue
      End Property

4. Add the following code to the Form Module (Form1):

      Option Explicit

      Private Sub Form_Click()
         Dim myclass As New Class1
         Dim sum As Integer
         Dim prop As Integer

         ' Example of calling a method with CallByName
         ' equivalent to -- sum = myclass.Multiply(12, 12)
         sum = CallByName(myclass, "Multiply", VbMethod, 12, 12)
         MsgBox sum

         ' Example of a property let with CallByName
         ' equivalent to -- myclass.MyProperty = 5
         CallByName myclass, "MyProperty", VbLet, 5

         ' Example of a property get with CallByName
         ' equivalent to -- prop = myclass.MyProperty
         prop = CallByName(myclass, "MyProperty", VbGet)
         MsgBox prop
      End Sub

5. Run the Project and click on Form1. A message box displaying the number
   144 and a message box displaying the number 5 are shown in succession.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now