Using data to specify forms/functions to open/call 
Author Message
 Using data to specify forms/functions to open/call

I have two scenarios, similar in nature, where I am trying to dynamically "do
things" in VB depending on values in a field within a (SQL Server) database table.

1) I want to use a character string containing a VB form name (eg. "frmTest") to
set a form object variable to point to the form, and then show it.
2) In a different scenario, I want to use a character string containing a
particular function name (which requires either no parameters, or one parameter
that is always the same no matter which function is called - haven't quite
decided yet!), to evaluate which function we're dealing with, and call it
(similar to the "Eval" statement in MS-Access).

Obviously I can do this by using a Select Case statement, then having all the
relevant form names or function names hard-coded within the Select Case, but is
there a way to make this entirely dynamic, and therefore decided upon at run-time
by the data alone?

Any help would be greatly appreciated. Thanks in advance, Darren.



Sat, 25 Oct 2003 09:10:12 GMT  
 Using data to specify forms/functions to open/call

Quote:
> 1) I want to use a character string containing a VB form name
> (eg. "frmTest") to set a form object variable to point to the form,
> and then show it.

This would be nice.  If you find something more
reasonable than my incomplete and wild speculations,
please post it here.

The TypeLib Information Objects (TLBINF32.DLL) provides
an interface to typelib info in ActiveX DLLs, EXEs, or
just plain *.tlb, *.olb files.  Perhaps there's a hitch, but
occurs to me that you could use this library to query
"yourself" to find out form names and clsids.

From there, though, I don't know if you could use this
information to create a form within your process--or even
at all.  It's a great library, though, if you want to create an
object browser. (small consolation)

Quote:
> 2) In a different scenario, I want to use a character string
> containing a particular function name (which requires either no
> parameters, or one parameter that is always the same no matter
> which function is called - haven't quite decided yet!), to evaluate
> which function we're dealing with, and call it (similar to the "Eval"
> statement in MS-Access).

Check out the CallByName statement in vb.  It allows
you to call a named function with an arguments list.  This
works well for your second goal.

The bad news about this statement is that if an error
occurs within the function call, it will be turned into a
generic OLE error by the time you get it.

The aforementioned TLBINF32 dll has an Invoke, or
InvokeMethod (something like that) that behaves
similarily, but does not mangle errors.



Sat, 25 Oct 2003 12:28:22 GMT  
 Using data to specify forms/functions to open/call
Thanks for your thoughts Grinder.  I received a response earlier at www.experts-
exchange.com (posted my query to several forums, coz I was in a hurry) from an
all-round good guy (gal?) called AzraSound.

For the forms issue, he/she (they from now on!!) suggested to use the Forms.Add
("frmName") method, which works for what I want to achieve, after some minor
tweaking from their suggested code.  They also suggested several possible
solutions for the other issue, and by far and away the easiest is to use the
CallByName statement, as per your suggestion, with my functions set up in a class
module.

Quote:
-----Original Message-----
> 1) I want to use a character string containing a VB form name
> (eg. "frmTest") to set a form object variable to point to the form,
> and then show it.

This would be nice.  If you find something more
reasonable than my incomplete and wild speculations,
please post it here.

<snip rest of response>



Sat, 25 Oct 2003 14:56:42 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Opening a form an using function fron an other template

2. Opening a form with parameters using Data Connection

3. Opening databases without using Forms and placing the data control objects on them

4. Opening databases without using Forms and placing the data control objects on them

5. Opening specified Word documents per record in a form

6. Using string to specify method to call on object

7. using a variable to specify field name in dlookup function

8. Calling a sub or function using a variable through another sub or function

9. Forms Collection: Using it to Open Forms by Passing the Form Name as a String Variable

10. Calling A Function In One Form From A Funciton In Another Form

11. Acc97: Specifying /CMD parameter when opening database via open dialog

12. Saving open file and opening new file at a specified time of day

 

 
Powered by phpBB® Forum Software