Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Passing variabels between forms
Message
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00252373
Message ID:
00252502
Vues:
13
>In making a system, I am affraid to use a lot of global/public variable, cause it's can decrease the performance of the system. Is that right??
>
>The problem is I want to pass the variabel between forms and I don't want to use global/public variable. Is that possible?. Cause in C and FoxPro are possible to do this.
>
>The scenario is like this:
>In form A, there is a "search" button, if this button is pressed, it will call form B. Form B is used for searching database. If the user clicks the record, form B will be closed and will reply the key that user choose to form A. The problem is I want to use form B as a flexible form, so form B can search every database and table. I only want to pass variables to form B.
>Variables that are needed in form B are:
>1. Variable for database's name
>2. Variable for table's name
>3. Variable for fields
>4. Variable for key
>
>Variable that will be reply from form B is only Key variable
>
>Anybody can help me??
>
>-Frans-

There is a least 2 ways:
1- Declare public variables in the General Declarations sections of your Form B. Then from your Form A, call FormB.Variable1 = ... and then show your Form B.

2-The other way (the one I prefer most) is to declare a public method accepting parameters and, in your case, returning a parameter. So, in your form B, you will have something like this:
Public Function MyMethod(p1 As ..., p2 As ...) As ...
'do something with your parameters
Me.Show vbModal 'Have to be modal not to return to form A immediately
MyMethod = ...
End Function

To call this, from your form A call this:
answer = FormB.MyMethod(1,2)
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform