Variable Decloration 
Author Message
 Variable Decloration

With out creating a module to declare a Global Variable, how do I declare a
variable in a parent form so the child form called within can access it ??

Thanks Much
Ryan Shaw



Thu, 14 Feb 2002 03:00:00 GMT  
 Variable Decloration
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Quote:
>With out creating a module to declare a Global Variable, how do I
declare a
>variable in a parent form so the child form called within can access

it ??

In the parent form declare the variable as public. Within the child
form, reference the variable as <formname>.<varname>

Example: Assume the parent form is named frmParent. You want to make
variable "x" accessible.

In the parent form declare:

        Public x as long

In the child form reference the variable with

        frmParent.x

Hope this helps.
-----BEGIN PGP SIGNATURE-----
Version: PGP 5.5.5

iQA/AwUBN8mL2RjeBTlTzg1DEQK7rwCePTJfY42439BnnJZTiPcrltJlcngAoKPW
sVPZna4e5bt3hC0JXNE/eP/D
=tkVZ
-----END PGP SIGNATURE-----

---Michael
"Congress shall make no law ... abridging the freedom of speech."
www.weblore.com/soapbox
New: TANSTAAFL - On Federal Funding

To send email, remove "nospam"



Thu, 14 Feb 2002 03:00:00 GMT  
 Variable Decloration
You can declare a Public variable in any form and call it from any other
form
if you add this line in the parent form
Public VarName
you can call it from your child form or from any other form
ParentForm.VarName
the variable will looks like a property of the parent form.
This call will load the parent form if it is not loaded.

Kamel

Quote:

>With out creating a module to declare a Global Variable, how do I declare a
>variable in a parent form so the child form called within can access it ??

>Thanks Much
>Ryan Shaw



Thu, 14 Feb 2002 03:00:00 GMT  
 Variable Decloration
It might be better programming practice to add a set of property procedures
(Get, and Let/Set) instead of using a public variable.  In general, public
variables should be avoided in class modules (and yes,  a form is a class
module).

To implement the same property as Kamel did, I would do the following in the
form module:

     In the Declarations section:
         Private mvarVarName as VarType

     Then, at the end of the module, I would add:

         Public Property Get VarName() As VarType
             VarName = mvarVarName
         End Property

         Public Property Let VarName (ByVal pNewVarName As VarType)
             mvarVarName = pNewVarName
         End Property

HTH,
ian

Quote:

> You can declare a Public variable in any form and call it from any other
> form
> if you add this line in the parent form
> Public VarName
> you can call it from your child form or from any other form
> ParentForm.VarName
> the variable will looks like a property of the parent form.
> This call will load the parent form if it is not loaded.

> Kamel


> >With out creating a module to declare a Global Variable, how do I declare a
> >variable in a parent form so the child form called within can access it ??

> >Thanks Much
> >Ryan Shaw



Sat, 16 Mar 2002 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Variable Decloration

2. Procedure Decloration does not match event

3. print variable, variable, variable etc

4. Referencing Global Variable from a variable

5. Error msg: Object variable or With block variable not set

6. Expanding a variable or referencing a field within variable

7. Obfect variable or With block variable not set

8. How do I use contents of variable as field name(db!rst!variable)

9. converting an object variable (name of a file) into a string variable

10. Object Variable With Variable Not Defined Error

11. how do i convert a string variable to a control variable

12. Object variable or With block variable not set when calling COM Dll

 

 
Powered by phpBB® Forum Software