Login Register






Get, Set, Let, and Invoke Easily! filter_list
Author
Message
Get, Set, Let, and Invoke Easily! #1
Yo.

So I made this for a project I'm making currently and figured some others here might find it useful! 

It's very simple in concept, but is a pretty hidden function in VisualBasic.Interaction and I very seldom see it used. It just happened to cross my mind as I was making a separate function for the task of getting the text of each text box that I'd eventually have to get text from, let alone setting text. 

I'll also mention that you can call this from a separate thread and not have to worry about cross threading exceptions as I've got that handled yo.

This code is very easy to use, I won't go into explaining why it works, but I will explain how to use it.
(This may or may not also be useful in crypters Wink )


Code:
   Function UIValue(_source As Object, _property As String, Optional _Method As CallType = CallType.Get, Optional _args As Object = Nothing)        Dim _Obj = Nothing        Try            Invoke(New MethodInvoker(Sub()                                         If Not _args = Nothing Then                                             _Obj = CallByName(_source, _property, _Method, _args)                                         Else                                             _Obj = CallByName(_source, _property, _Method)                                         End If                                     End Sub))        Catch            'Handle errors here        End Try        Return _Obj    End Function

Example of setting a text box's text:
Code:
UIValue(Textbox1, "Text", CallType.Set, New Object() {"Hey look at that!"})
Example of getting a text box's text:
Code:
Dim Text1Value As String = UIValue(Textbox1, "Text")

If you don't get the jist by now, you can input any property into the second parameter and go about your business from there, eg "Enabled", "ForeColor", "Visible", etc. 

The third parameter modifies how CallByName accesses the Source Object.

Get - Used when a property value is being retrieved
Let - Used when an Object's property value is being determined
Method - Used when invoking a method
Set - Used when a property's value is being set

An example of method would be PerformClick, a button's property:
Code:
UIValue(Button1, "PerformClick", CallType.Method)

Reply