Create a public variable in the general declarations of the form (Public strData as String). Then from the calling location, load the form in the following manner:
Public variables will certainly work, but are a poor programming practice, as you will have no control over values assigned to the variable, nor will you know when a value is assigned. I NEVER use public variables for these reasons. Add a new Property to the form to pass values. This will allow you to validate the incoming value, as well as execute other code inside the form when a new value is passed. Trust me, as your program grows and becomes more complex, little things like this become more important. Program defensively!
1. On the form that you want to call (let's call it MyForm), create a label, and name it lblParameter. Set the lblParameter.Visible property to false.
2. Place the following statement in the code that will call the form:
MyForm.lblParameter.Tag = "ValueToPass"
This will (a) place the string "ValueToPass" into MyForm.lblParameter.Tag, and (b) automatically load/show the form. Within the form's code, you can then use the value in lblParameter.Tag for whatever purpose you wish.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.