Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 17th, 2005, 07:53 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default 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
 
Old January 17th, 2005, 09:02 AM
Authorized User
 
Join Date: Jan 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to yeetesh
Default

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


 
Old January 17th, 2005, 09:48 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

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.
 
Old January 18th, 2005, 11:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

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
 
Old January 19th, 2005, 12:45 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 463
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to madhukp
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing variable to a public variable Hudson40 Access VBA 2 February 25th, 2005 06:23 AM
Passing a variable mrideout BOOK: Beginning ASP.NET 1.0 3 August 6th, 2004 02:57 PM
Passing a variable trekmp ADO.NET 1 March 4th, 2004 01:57 PM
form variable passing with popups and other... jman11587 Beginning PHP 4 February 18th, 2004 10:31 PM





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