Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable value from user-entered string?

Status
Not open for further replies.

nickd87

Technical User
Jan 18, 2006
110
AU
Hi everyone

I'm not quite sure how to describe what I am asking so I will just give you the situation.

I have a textbox and I want a user to be able to type in a string which will actually be the name of a variable declared in the application and I want a message box to appear with its value.

The only way I can think of for doing is having a select statement and run through all the variables.. but I have hundreds! And I am hoping there is a much better way, although I will admit the request is a bit unusual.

Here's to hoping...
 
The only thing I know of that is even remotely similar is the CallByName function, but that works on an object, not a variable.

Can you explain why you would want end-users to have such functionality? The "insides" of your application should properly remain a mystery to them.


 
>but that works on an object, not a variable.

Works on a variable (property) if it belongs to an object.

x=CallByName(Form1,"VariableName",VbGet)

"VariableName" is Method a or a Property Get/Let (which a variable uses behind the scences).
 
SBerthold,

Are you able to explain further? Is it just that this wont work on an ordinary declared variable - as in I need to do something more for it to work? I'm having trouble using it.

JoeAtWork - it's primarily for debugging purposes. I want to be able to telnet to it and grab some variable values while it's running.
 
>wont work on an ordinary declared variable

The variable needs to be public, meaning declared in the declaration section of the form. Just as accessing a method or property as in:

Form1.BackColor
Form1.Show
Code:
Option Explicit
Public MyLong As Long

Private Sub Command1_Click()
    MsgBox CallByName(Me,"MyLong",vbGet)
End Sub
 
Thanks.

Modules are no go's but Classes are OK.

Thanks guys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top