p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   VB How-To (http://p2p.wrox.com/forumdisplay.php?f=78)
-   -   passing a variable from one form to another (http://p2p.wrox.com/showthread.php?t=23974)

madhukp January 17th, 2005 07:53 AM

passing a variable from one form to another
 
May I know what is the best way to pass one variable from one form to another in VB 6.0 ?

For e.g., I have a form which lists all employees after a search. On clicking an employee, I should show the full details of the employee, for which I need to pass the id of employee to the second form.

Currently, I am setting a global variable (in a module) and accessing it from the above 2 forms - once for setting it and once for using it. But this does not seem to be a professional method and not scalable also. When number of values to be passed increases I will have hundreds of public variables in module.

Is there any other way ? Something like querystring in web environment ?

Thanks

Madhu

yeetesh January 17th, 2005 09:02 AM

I dont think there is anything like Querystring in VB,atleast I haven't used it.
Instead of declaring public variables in modules and then retrieving or setting them you can always declare public variable in the form itself and then access it through form.YourPublicVariableName



madhukp January 17th, 2005 09:48 AM

Hello Yeetesh,

Thanks for the reply. I got the idea.

But, there is a problem. The employee details form is a general one to be used in many places. From whereever they click an employee, this form will be shown. Sometimes, it can happen that the employee search form is not open and employee details form is shown from another place. Then reference to frmEmpList gives an error. All these makes me confused.

Thanks for your suggestion. Let me see if any design change is possible so that I can achieve this.

SerranoG January 18th, 2005 11:41 AM

There are a few options for saving employee ID and using it in many forms.

1) Leave the form with employee ID open but hide it when other forms open. Then reference it with Forms.NameOfForm.Form.EmployeeID (use your real form and field names here).

2) Store the employeed ID in a temporary table with that one field and any other data you want to be available to other forms. Reference the ID from there. You can close the form instead of just hiding it.

3) Create a global variable for employee ID and store it there. You can close the form instead of hiding it.


Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division

madhukp January 19th, 2005 12:45 AM

Thanks for all the replies.

I have finally decided to use a public array combined with a list of constants for storing variables that are to be passed between pages.

something like

CONST CURRENT_PROJECT_ID = 1
CONST CURRENT_CIRCUIT_ID = 2
....

Then a public array arrParameters(100)

arrParameters(CURRENT_PROJECT_ID) stores the current project id and so on.

Thanks again for giving ideas.


All times are GMT -4. The time now is 09:34 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.