Event Trigger Problem

wizzard

New member
Joined
Apr 19, 2007
Messages
2
Programming Experience
1-3
I have a really strange ad potentially basic problem. I am trying to do the following. I need to populate a text box from a list boxes selected options. To do this I have 2 forms you click on a button with on the form with the text box and it passes some values into a global variable and opens the modal form with the list box. When I click ok on the list box it passes the selected values into a global variable and closes. Now what I need to happen is after the second form has closed, the first form must put that variable’s value into the text box on form 1. What event will I use? I am so stumped.:mad:
 
Global variable? That sounds like a lazy non-OOP shared variable, am I right? What you should do is to create the second form instance, pass it the value, ShowDialog it, and when that call returns you retrieve the value. Here is the pseudo setup:
VB.NET:
class firstform
 
sub buttonclick
    dim f as new secondform
    f.input = "give this to second form"
    if f.showdialog = dialogresult.OK then
        textbox1.text = f.output
    end if
    f.dispose
end sub
 
end class

VB.NET:
class secondform
 
public input, output as string
 
sub formload
    'make some use of the input variable
end sub
 
sub listboxchange
    'put the selection in the output variable here perhaps?
end sub
 
end class
This is how you normally configure dialogs and retrieve values from them after they is shut. (just compare with any of the standard dialogs) The code in first form will not continue to next code line after ShowDialog until the dialog is closed, and this is what first form needs to know to start getting the return.

With this basic set up you have some more options, I used here just a public variable and formload to use it. You can use a form constructor where you necessary adjustments in second form when it is created (Sub New with parameters). You can also use a public property, if the same property is also returned/modified it makes sense to use getter+setter property. Like the constructor the property setter enables you to configure the class right away as the value is set.
 
Shot

"Global variable? That sounds like a lazy non-OOP shared variable, am I right?" Yeah is is a module with a whole lot of public variables in it. Lazy i know, but am this point i am so far behind, it is all about getting finished on time, not doing it properly. lol.

Thanks for the help. I didn't realise that the line after showdialog triggers after the dialog closes. This will fix the problem that about 8 forms call the same dialog, as i can put the insert code into the click event.


You are the man, shot.
 
Back
Top