|
-
Feb 9th, 2003, 12:09 PM
#1
Thread Starter
Fanatic Member
callbyname
can someone give me an example of using the callbyname function? plus give me a little information on what it does exactly? thanks from ahead!
Best Regards,
seec77
If you helped me, cosinder yourself thanked.
Get each and every Garfield strip here!
Here you can get all Calvin & Hobes strips!
Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!
I am 33% addicted to Counterstrike. What about you?
I am 23% addicted to Star Wars. What about you?
I am 0% addicted to Tupac. What about you?
-
Feb 9th, 2003, 12:58 PM
#2
It calls methods, or sets/retrieves property values by the name of the method/property. Here's an example...
VB Code:
MsgBox CallByName(Text1, "Text", VbGet)
It will return the value of the Text property. To set it...
VB Code:
Call CallByName(Text1,"Text",vbLet, "Some Text")
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Feb 9th, 2003, 01:38 PM
#3
Member
seec77 ,
Here is some more information. I have never used this but here's some info out of one of my reference books.
The CallByName function allows you to use a string to specify a property or metod at run time.
My intellsense says:
CallByName(Object As Object, ProcName As String, CallType As VBCall Type, Args() As Variant)
The Programmer's Guide says:
Result = CallByName(Object, ProcedureName, CallType, Arguments())
The first argument to CallByName takes the name of the object that you want to act upon. The second argument ProcedureName, takes a string containing the name and method or property procedure to be used. The CallType takes a constant representing the type of procedure to invoke: a method (vbMethod), a property let (vbLet), a property get (vbGet), or a property set (vbSet). The final argument is optional, it takes a variant array containing any arguments to the procedure.
Suppose this was a server app, called MathServer, that you wished to add a new SquareRoot funcion to. Your app has two textbox controls: Text1 has the expression to be evaluated; Text2 is where you enter the name of the function. The following code should then work in the click event of a command button to invoke the SquareRoot function on the expresion in Text1:
Private Sub Command1_Click()
Text1.Text = CallByName(MathServer, Text2.Text, vbmetod, Text1.Text)
End Sub
If you enter "64/4" in Text1 and "SquareRoot" in Text2, which should return "4 " in Text1. If you enter an invalid string in Text2, or if the string contains the name of a Property instead of a method, or if the method has an additional required argument, you will get a run-time error. So you will need to add robust error handling to anticipate these or any other errors that might occur.
You will need to wiegh its usefulness against performance problems. CallByName is a little slower than late-bound calls and if you call it repeatedly, say from inside a loop it could have a severe effect on your apps performance.
Whew.... hope this helps.
Last edited by Jerome W. Norgren; Feb 9th, 2003 at 01:42 PM.
Jerome W. Norgren
"Know how to ask. There is nothing more difficult for some people, nor for others, easier."
- Baltasar Gracian
-
Feb 9th, 2003, 01:53 PM
#4
Thread Starter
Fanatic Member
wow thanks guys
great job! but one more thing is on my mind... say i want to do a remote control prog, and i want to send another computer a command to do...
say i am the remote comp trying to send another comp a function telling it to do a msgbox saying "hello"...
so something like this:
VB Code:
Private Sub Form_Load()
winsock1.senddata("msgbox("+chr(34)+"hello"+chr(34)+")") 'what it does here is send the other computer the string msgbox("hello") through a winsock!
End Sub
this is the computer receiving the data:
VB Code:
Private Sub Winsock1_Receivedata(bytesLong as integer)
Dim Temp as String
winsock1.getdata Temp
'here i want it to execute the temp string he got from the other remote comp
End Sub
Best Regards,
seec77
If you helped me, cosinder yourself thanked.
Get each and every Garfield strip here!
Here you can get all Calvin & Hobes strips!
Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!
I am 33% addicted to Counterstrike. What about you?
I am 23% addicted to Star Wars. What about you?
I am 0% addicted to Tupac. What about you?
-
Feb 9th, 2003, 08:17 PM
#5
PowerPoster
You are trying to do a compile time operation at run time. Won't work. You'll have to write your own parser to decode the sent string and your own logic to interpret (execute) it. The compiler (which is what VB uses to parse such stuff) is LONG GONE by the time the string is received and so is not available to parse it and turn it into executable code.
-
Feb 9th, 2003, 09:49 PM
#6
Hyperactive Member
Solution...
Send something like:
ON the sender program put something like this
Private Sub Form_Load()
Winsock1.Senddata "<MSG>Hello people"
End Sub
And on the receiver put somthing like this...
Private Sub Winsock1_Receivedata(bytesLong as integer)
Dim Temp as String
Winsock1.Getdata Temp
If Left(Temp,5) = "<MSG>" Then
Msgbox Mid$(Temp, 6)
End If
End Sub
Aight...let me explain...
What you're doing is sending a string with the tag <MSG>followed by what you want it to send. When the receiver picks it up it will get the whole string including the tag. So what you do is separate the tag from the rest of the string to be displayed (also know as parsing a string)
That's what the Left(Temp,5) function does. It takes the first 5 characters in the variable Temp and if they are equal to <MSG> then it know that anything after the tag is displayed in a message.
So it then parses the string with the Mid$(Temp,6) and what this does is returns the rest of the string starting from the 6th character (the next character after the tag)...
Is that simple enough for you? Aight...good luck then
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
-
Feb 9th, 2003, 11:33 PM
#7
Stuck in the 80s
Protocol, do you know that you can surround your code with vbcode tags so that you don't have to manually color keywords?
So this: [vbcode]Private Sub Form_Load()[/Highlight]
Will become:
Just thought I'd let you know.
-
Feb 9th, 2003, 11:35 PM
#8
Hyperactive Member
lol...
THAT I did not know...
I'm so accustomed to the predefined bbcode scripts, that I didn't think of searching for that one...
Tanx Hobo
Preciate it.
If my post has been helpful, then please rate it accordingly...
If it has solved your question(s), then don't forget to mark the thread as "[Resolved]"... thank you.
-
Feb 10th, 2003, 08:08 AM
#9
Thread Starter
Fanatic Member
Originally posted by phinds
You are trying to do a compile time operation at run time. Won't work. You'll have to write your own parser to decode the sent string and your own logic to interpret (execute) it. The compiler (which is what VB uses to parse such stuff) is LONG GONE by the time the string is received and so is not available to parse it and turn it into executable code.
i don't really understand in all that stuff... do you know if there is a parser that can execute strings at run-time?? and by the way thanks protocol but i allready thought of that...!
Best Regards,
seec77
If you helped me, cosinder yourself thanked.
Get each and every Garfield strip here!
Here you can get all Calvin & Hobes strips!
Damn UComics! It was probably unprofitable for them to allow us to just download Garfield and Calving & Hobes strips... so they made folder indexing unallowed on their server!!!
I am 33% addicted to Counterstrike. What about you?
I am 23% addicted to Star Wars. What about you?
I am 0% addicted to Tupac. What about you?
-
Feb 10th, 2003, 09:40 AM
#10
Frenzied Member
Originally posted by seec77
i don't really understand in all that stuff... do you know if there is a parser that can execute strings at run-time?? and by the way thanks protocol but i allready thought of that...!
Use the Script Control. Take a look at my last posts here.
"Brothers, you asked for it."
...Francisco Domingo Carlos Andres Sebastian D'Anconia
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
|