Re: Interaction Between FORM
Read up on using custom properties to manage the movement of data between forms.
Re: Interaction Between FORM
1. If you change Text1 then the Change event must be firing.
2. To refer to something on another form you need to include the name of the other form like Form.Text1.Text = "blah"
3. Set some Public variable in a code module or check the Forms collection.
4. ???
Re: Interaction Between FORM
Hi, thanks
Martin
1. Yes, textbox is change but still change event doesn't firing.
2. I set FORM1 to become object on FORM2, something like
on FORM1:
Dim frm1 As FORM1
Set frm1 = New FORM1
Set frm1.fMain = Me
frm1.Show
on FORM2
Public fMain As FORM1
is that not the correct way.
when on FORM2 i'm using FORM1.textBox.text="BLAH BLAH", it will show up FORM1
ones again, although it already open.
3. I'm going to try that, thank
4. i want FORM2 to show up exactly under control on FORM1 (while FORM1 can be move)
Thanks
Re: Interaction Between FORM
Re: Interaction Between FORM
umm, regarding your event problem. The textbox change event is firing - just not on the form you want it to. If you create a new instance of a form using:
VB Code:
Dim frm1 As FORM1
Set frm1 = New FORM1
Set frm1.fMain = Me
frm1.Show
then you must continue to refer to that using an object reference - in the manner that the frm1 object is being used to show the instance of form1 (however since the varaible is local to the sub, you won't be able to use that particular object to refer to that form outside of that procedure - you'd need a modular level or public object).
By refering to that object as Form1:
VB Code:
FORM1.textBox.text = "BLAH BLAH"
you are creating (and setting the textbox text) of a new instance of Form1 - different from the one that you are showing.
Are you using multiple instance of Form1 in your program? If not, then there is no need to create a new insatnce of the form using Set frm1 = New FORM1. Just refer to the form using it's design-time name.
Re: Interaction Between FORM
In Form2 you should use: fMain.Text1.Text = "blah" since fMain contains a reference to the form you have loaded.
Re: Interaction Between FORM
Yes Joacim i'm using - fMain.Text1.Text = "blah" -
bushmobile,
No i Don't create multiple instance of FORM1 in my program, but if i'm refer it using design time name (FORM1) it will open FORM1 ones again although it already open, btw FORM1 is MDI Child. So waht is best approach for my purpose?
About, textbox event change don't firing, it's resolved. It was my mistake, since i create usercontrol from textbox and forget to add Raisevent Change on that usercontrol event change.
Set position of FORM2 to show up on exact location of control FORM1 (as my question #4) also resolved. I got it from vbaccelerator.com
But now if try to moving variables between FORM. Declared it as Public on module is last option.
I was interrest wit custom properties, and learning it right now. My question is what about if FORM2 should return variable more than one? better using array on Custom Properties or create custom properties .value1 , value2, so on...?
And i still don;t get it how FORM1 know that FORM2 has gone? or how to tell FORM1 when FORM2 has gone?
In my application when some button on FORM1 get clicked FORM2 popup exactly under this button. When some control from FORM2 get clicked TEXTBOX on FORM1 value get changed. When user clicked outside FORM2 FORM2 get unload. So where is correct time to tell FORM1 that FORM2 has gone?
Thanks guy
Re: Interaction Between FORM
Quote:
Originally Posted by barianto
bushmobile,
No i Don't create multiple instance of FORM1 in my program, but if i'm refer it using design time name (FORM1) it will open FORM1 ones again although it already open, btw FORM1 is MDI Child. So waht is best approach for my purpose?
Then you are creating multiple instances of Form1. VB automatically creates an object of a Form with the same name as the class. This object is however doesn't have any instance until you start to use it, which you do when you use the name Form1. That's another instance of the Form apart from the one you've created with the New keyword.
Re: Interaction Between FORM
Well i don't need create multiple instance in my program, So what should i do?
Re: Interaction Between FORM
Re: Interaction Between FORM
Since Form2 has a reference to the form that showed it (fMain) simply create a public sub in Form1 which you call from Form2 when it's time to unload itself. You can pass any values back to this sub in Form1, just remember that in Form2 this form is called fMain and nothing else.
VB Code:
'In Form1
Public Sub Form2Closes(ByVal someValue As Long, ByVal anotherValue As String)
'do whatever
End Sub
'in Form2, for example in the Unload event
Private Sub Form_Unload(Cancel As Integer)
'Let Form1 know that it is closing time :)
Call fMain.Form2Closes(25, "Hello world")
End Sub
Of course the values 25 and "Hello world" above should be replaced with whatever values you want to pass back to Form1.
Re: Interaction Between FORM
Okay, just frm1.show
Guys thanks all for your kindly response, that give me much new idea how thing can be done in vb.
All my problem had been answered now:
1. It's my own fault, when textbox change, it's definitely should firing event textbox.change. I managed to found where the problem is.
2. I'm using CUSTOM PROPERTIES
3. Also using CUSTOM PROPERTIES
4. I'm using this
VB Code:
Dim tR As RECT
GetWindowRect picCommandbar.hwnd, tR
FORM2.Move tR.Left * Screen.TwipsPerPixelX, (tR.Bottom + 1) * Screen.TwipsPerPixelY
picCommandbar is reside on FORM1
Cheer :)