• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 136
  • Last Modified:

passing a string vairable between forms

I have two forms.  A menu in formA creates a string variable.  I want to then open formB and pass that variable to a function in formB.  how do I do it?  Thanks.
Eg:

formA menu_click()

string= "bla bla"
formB.show  'open the form
formB.functionname string  'pass the string to the function                             in formB

formB
functionname(string)
0
SE081398
Asked:
SE081398
1 Solution
 
kamallCommented:
There are three ways to accomplish this:

1. Make the string variable public by declaring it in a Module (.BAS), and then when FormB is loaded, call the function passing it the variable whose value was set in FormA.

2. Set a property of one of the controls in FormB, for example the Caption property of a Label control on FormB to be the value of the string you set from FormA. When FormB is loaded, read the caption of the label, execute the function, and set the label's caption to nothing or anything you want.

3. Create a new private property in FormB, and set the value of this property to be the string value you set from FormA.

I personally prefer the first two solutions.

Regards.
0
 
viktornetCommented:
I personally prefer the first solution :)
0
 
kamallCommented:
Thanks viktornet, thats what I always use :)
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
viktornetCommented:
:)
0
 
kamallCommented:
:)))
0
 
viktornetCommented:
;-))
0
 
stefanxCommented:
Hmm, why not just declare the string in form1 as public i.e in Form1 :

Public strMyString AS String

You can then refer to the string from anywhere in your project as Form1.strMyString
0
 
viktornetCommented:
Module.bas would be a better idea as kamall has previousl mentioned because you don't need to use the Form1.strMyString, but simply can write strMyString from anywhere in your program....

..-=ViKtOr=-..
0
 
chee68Commented:
If it just involve FormA and FormB only, personally i prefer solution 2 compare to solution 1.  This would minimise the variable that you are going to use in the project.  This is useful when come to the maintenance of the program.(If the project involve a lot of form).

Thanks

chee
0
 
SE081398Author Commented:
I ended up using a global variable in a module. due to the situation, didn't want to but had to.  I was hoping to limit the declaration of the variable to just the forms because only these two forms will use the variable.  I liked stefanx's idea.  Unfortunately, there are 6 sub menus that declare a new string value depending on which submenu is clicked.  Using  form.stringval will cause an error. there are 5 stringval's that are null and 1 with a value.  Not knowing which menu will be clicked will point form.stringval to 6 possible variables.  So I had to use a global variable.  Kamall's 2,3 are creative and I could probly implement them at some time.  

Thank you for your help.  good ideas!!
0
 
kamallCommented:
You are welcome SE.
Best regards.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now