Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 17th, 2005, 07:53 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
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
Reply With Quote
  #2 (permalink)  
Old January 17th, 2005, 09:02 AM
Authorized User
 
Join Date: Jan 2005
Location: , , India.
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


Reply With Quote
  #3 (permalink)  
Old January 17th, 2005, 09:48 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
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.
Reply With Quote
  #4 (permalink)  
Old January 18th, 2005, 11:41 AM
Friend of Wrox
Points: 4,007, Level: 26
Points: 4,007, Level: 26 Points: 4,007, Level: 26 Points: 4,007, Level: 26
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Lansing, Michigan, USA.
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
Reply With Quote
  #5 (permalink)  
Old January 19th, 2005, 12:45 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: Cochin, Kerala, India.
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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 12:25 AM.


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