Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

passing a string vairable between forms

Posted on 1999-07-24
11
Medium Priority
?
134 Views
Last Modified: 2010-04-30
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
Comment
Question by:SE081398
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 7

Accepted Solution

by:
kamall earned 150 total points
ID: 1527214
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1527215
I personally prefer the first solution :)
0
 
LVL 7

Expert Comment

by:kamall
ID: 1527216
Thanks viktornet, thats what I always use :)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Expert Comment

by:viktornet
ID: 1527217
:)
0
 
LVL 7

Expert Comment

by:kamall
ID: 1527218
:)))
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1527219
;-))
0
 
LVL 8

Expert Comment

by:stefanx
ID: 1527220
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
 
LVL 10

Expert Comment

by:viktornet
ID: 1527221
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
 

Expert Comment

by:chee68
ID: 1527222
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
 
LVL 3

Author Comment

by:SE081398
ID: 1527223
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
 
LVL 7

Expert Comment

by:kamall
ID: 1527224
You are welcome SE.
Best regards.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question