Results 1 to 13 of 13

Thread: Interaction Between FORM

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Interaction Between FORM

    Interaction between form

    Hi, i have two form, One is MDI Child (FORM1) and another is "normal form"
    (FORM2) that i show from FORM1 with "vbModelless". When
    some control on FORM2 get clicked "text" property of
    "textBox" control on FORM1 change. I was able to do
    that, but Event "textbox.change" on textbox control
    FORM1 didn't executed. On this change event i change
    value almost every control on FORM1 and execute some
    function on FORM1.

    My question is
    1. How is the proper way to achieve my goal above?

    2. How to passed variables between FORM1 to FORM2? so
    FORM2 will act properly according to what variables been
    pass to it or if i change variables that been pass to
    FORM2, how FORM1 wil recognize it's new Value?

    3. How FORM1 know that FORM2 has gone?

    4. How to position FORM2 relative on some control on
    FORM1 (FORM1 can be move)? FORM2 will be launch wen
    "COMMANDBUTTON" on FORM1 get clicked, i want FORM2 popup
    exactly under this "COMMANDBUTTON".

    All you VB Guru please help me....

    Thanks.

    PS: i will away for a while so i'm sorry if i'm not able

    to response to you follow up question.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Interaction Between FORM

    Read up on using custom properties to manage the movement of data between forms.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    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. ???

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: Interaction Between FORM

    Bump

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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:
    1. Dim frm1 As FORM1
    2. Set frm1 = New FORM1
    3. Set frm1.fMain = Me
    4. 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:
    1. 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.

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Interaction Between FORM

    In Form2 you should use: fMain.Text1.Text = "blah" since fMain contains a reference to the form you have loaded.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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
    Last edited by barianto; Jul 16th, 2006 at 11:32 PM.

  9. #9
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: Interaction Between FORM

    Well i don't need create multiple instance in my program, So what should i do?

  11. #11

  12. #12
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. 'In Form1
    2. Public Sub Form2Closes(ByVal someValue As Long, ByVal anotherValue As String)
    3.     'do whatever
    4. End Sub
    5.  
    6. 'in Form2, for example in the Unload event
    7. Private Sub Form_Unload(Cancel As Integer)
    8.     'Let Form1 know that it is closing time :)
    9.     Call fMain.Form2Closes(25, "Hello world")
    10. End Sub
    Of course the values 25 and "Hello world" above should be replaced with whatever values you want to pass back to Form1.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    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:
    1. Dim tR As RECT
    2.      GetWindowRect picCommandbar.hwnd, tR
    3.      FORM2.Move tR.Left * Screen.TwipsPerPixelX, (tR.Bottom + 1) * Screen.TwipsPerPixelY
    picCommandbar is reside on FORM1

    Cheer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width