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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Variable type?

Status
Not open for further replies.

rjmccorkle

Programmer
Aug 26, 2000
55
US
In R:Base there is a concept of an AMPERSAND VARIABLE. If there is an "&" at the start of the variable name it can be used as part or all of a command. An SQL command example would be:
SET VAR VWHERE = 'WHERE NAME IS NOT NULL'
SELECT ALL FROM table &VWHERE

Or the whole SELECT statement could be stored in a variable then executed by putting the ampersand in front of the variable and putting the ampersand variable on a line by itself.
Is there anything similar to this in VB? I am looking for something specifically to solve the problem of loading a form when its name is stored as a string variable and generally a tool to build commands from variables.
Thanks for any help.
Bob
 
A SQL statement is just a text string. You can parse any combination of string literals and variables into it. Use the concatenation or + operators to join strings.

For instance:

dim sSQLSelect as string
dim sSQLWhere as string
dim sSQLOrderBy as string

sSQLSelect="SELECT * FROM Table1 INNER JOIN Table2 on Table1.EmpID=Table2.EmpID "

sSQLWhere="WHERE Table1.Salary > " & Cstr(MinSalary) & " "

sSQLOrderBy="ORDER BY Table1.Salary"
...
rs.Open sSQLSelect + sSQLWhere + sSQLOrderBy


 
I'm not looking for the SQL portion of the command. I was wondering about the, in your example:
rs.Open
part or the whole command. Is there a way to set a variable equal to
"rs.Open sSQLSelect + sSQLWhere + sSQLOrderBy"
and then use the variable as a command?
My current problem is trying to load a form whose name is in a variable (actually stored as a control TAG). I have been unsuccesful in something like:

dim vForm as Form, vName as String
vName="frmForm"
vForm=vName
or
vForm.Name=vName

I am wondering if a workaround exists where a command can be "built" the way the SQL portion can be. Like:

vCommand="vForm=" & vName
vCommand

In RBase it would be:
&vCommand

Thanks for any help.
Bob
 
No, you cannot set a variable to a command and then run it by calling the variable later, that is not a part of a programming language...
Chris
 
Chris,

It may not be a feature of [red]PROGRAMMING LANGUAGE/u][/red], but I can assure you that is part of [red]A/u][/red] programming language - in fact it is relatively common.


MIchaelRed
There is never time to do it right but there is always time to do it over.
 
I would be interested in hearing more about this, in my experiences with C,C++,Perl, and VB I have never heard of this..
 
Chris,

I think rjmccorkle has pretty well described this function. It is commonly refered to as indirect addressing (or referencing). To some extent, the C++ pointer accomplishes this, although it is not the complete answer, at least as far as I know. In many languages, the practice of passing typed arguments also provides a partial soloution for the 'indirect' reference. Consider that you can (in VB) pass the name of a form to a function - as long as that argument is typed as "As Form" and VB will refer to the "object" properly - as long as it is already loaded.

 
Michael,

Ahh I see... I had to do alot of indirect addressing in MASM Assembler a couple of years ago (that is a "feature" of MASM). I guess this 'ampersand function' that rjmccorkle talks about is a function which automates this process to some degree. I wonder if it is implemented using pointers? It seems to me that would be the only way to do it, aside from using assembler (which uses internal pointers anyway). Thanks for the feedback. I Learn something new everyday!
Cheers
Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top