How to pass a property as an argument for userform controls?

Robert Todar

My issue

I'm creating a function that allows me to transition properties of controls, that are in a userform, from one state to another, creating an animation effect such as a custom drop-down list.

However, I can't seem to figure out if there is a way to pass the specific property as an argument, to keep the function more dynamic.

Simplified Example

Private Sub test()
    ' Transition the height of Frame1 additional 150
    transition Frame1, "Height", 13, 0.2, 150
End Sub

Private Function transition(obj As Object, objProperty As String, _
    framesPerSec As Integer, sec As Double, increment As Double)
    
    ' Calculate increment steps\time steps
    increment = increment / framesPerSec
    sec = (sec * 1000) / framesPerSec
    
    ' I tried the code below. Might be misunderstanding how `CallByName` works.
    ' I would use this in place of objProperty below
    
    'Dim Prop As Variant
    'Prop = CallByName(Obj, objProperty, VbLet)
    
    Dim index As Long
    For index = 1 To framesPerSec
        ' * Here is the example of what I'm trying to accomplish
        obj.objProperty = obj.objProperty + increment
      
        ' API sleep function (Milliseconds)
        Sleep sec
    Next index
End Function

I've tried looking at the VBA callbyname method, but can't seem to get it to work. Perhaps I didn't use it correctly when trying it?

I'm happy to take any feedback or help in any direction in how to pass control properties to a function?

Mathieu Guindon

Let's look at what's being invoked here:

Obj.objProperty = Obj.objProperty + Increment

Ignoring the fact that you're illegally treating a String local/parameter as a member of Obj, you have Obj.objProperty on both sides of the assignment, so syntactically, we have:

[object].[property-let] = [object].[property-get] + [parameter]

In other words, there's no way that can work with a single CallByName invocation: you need to first compute the RHS of the assignment, and in order to do that you need to invoke the Property Get member to read the current value, then add the increment, and then invoke the Property Let member to write the new value.

Dim currentValue As Double
currentValue = CallByName(obj, objProperty, vbGet)

So that's the read part. Then you can do the write part:

CallByName obj, objProperty, vbLet, currentValue + increment

Not sure what the Prop local Variant variable would be used for.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How pass an argument rails

分類Dev

How to pass a struct as an argument of a function

分類Dev

How to pass argument to the method definition of `[]`?

分類Dev

Ploting in a wxFrame, How to pass an argument?

分類Dev

How to pass flags as argument of urface/cli command?

分類Dev

How to pass a function as an argument for another function in julia?

分類Dev

How to pass None keyword as command line argument

分類Dev

how can i pass argument to celery task?

分類Dev

How to pass a boolean argument to a function to act as a switch?

分類Dev

PostgreSQL - how to pass a function's argument to a trigger?

分類Dev

How to pass the name of environment variable as an argument?

分類Dev

Python Logging: How to pass logging level as an argument

分類Dev

How to pass an argument through a button in tkinter

分類Dev

How to pass an external argument to reduce callback?

分類Dev

how to pass mutually exclusive argument as a variable

分類Dev

How to pass argument to javascript anonymous function

分類Dev

How to pass argument with char ( in remote path?

分類Dev

How to pass argument from template to view in Flask

分類Dev

how to pass a property by reference in C#

分類Dev

How to pass argument in multiprocessing function and how to use multiprocessing list?

分類Dev

Pass argument and function as argument in python

分類Dev

how to pass double value as a command line argument in java program

分類Dev

How to pass JVM arguments and script argument using GroovyShell?

分類Dev

how to pass a member function with args as an argument to another member function?

分類Dev

What argument to pass and how to find out its type?

分類Dev

How to pass in a second argument on ReactJS onSubmit function call

分類Dev

How can I evaluate an argument in a preprocessor macro to pass to sizeof?

分類Dev

How to pass an instance method, that uses instance variables, as argument to another function?

分類Dev

How to set Interval , clear Interval and pass an argument (timer)

Related 関連記事

  1. 1

    How pass an argument rails

  2. 2

    How to pass a struct as an argument of a function

  3. 3

    How to pass argument to the method definition of `[]`?

  4. 4

    Ploting in a wxFrame, How to pass an argument?

  5. 5

    How to pass flags as argument of urface/cli command?

  6. 6

    How to pass a function as an argument for another function in julia?

  7. 7

    How to pass None keyword as command line argument

  8. 8

    how can i pass argument to celery task?

  9. 9

    How to pass a boolean argument to a function to act as a switch?

  10. 10

    PostgreSQL - how to pass a function's argument to a trigger?

  11. 11

    How to pass the name of environment variable as an argument?

  12. 12

    Python Logging: How to pass logging level as an argument

  13. 13

    How to pass an argument through a button in tkinter

  14. 14

    How to pass an external argument to reduce callback?

  15. 15

    how to pass mutually exclusive argument as a variable

  16. 16

    How to pass argument to javascript anonymous function

  17. 17

    How to pass argument with char ( in remote path?

  18. 18

    How to pass argument from template to view in Flask

  19. 19

    how to pass a property by reference in C#

  20. 20

    How to pass argument in multiprocessing function and how to use multiprocessing list?

  21. 21

    Pass argument and function as argument in python

  22. 22

    how to pass double value as a command line argument in java program

  23. 23

    How to pass JVM arguments and script argument using GroovyShell?

  24. 24

    how to pass a member function with args as an argument to another member function?

  25. 25

    What argument to pass and how to find out its type?

  26. 26

    How to pass in a second argument on ReactJS onSubmit function call

  27. 27

    How can I evaluate an argument in a preprocessor macro to pass to sizeof?

  28. 28

    How to pass an instance method, that uses instance variables, as argument to another function?

  29. 29

    How to set Interval , clear Interval and pass an argument (timer)

ホットタグ

アーカイブ