Results 1 to 12 of 12

Thread: Closing a Modal form

  1. #1

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question Closing a Modal form

    with vb6;

    is there any thing special in closing a modal form which is having a MMcontrol and a timer apart from stopping both;

    i am having a formMain ( main) with two text boxes and one timer,
    private sub timer()
    if me.text1.text = me.text2.text then
    formModal.show
    formModal.txtMirror1.text = me.text1.text
    formModal.txtmirror2.text = me.text2.text
    else
    unload formModal
    end sub
    .................................................
    as the formModal opens MMcontrol will play and timer will
    activate as same when the formModal closes it disables
    ....................................................
    but i shocked why the formModal retains the previous properties set (viz textbox values) even after unloading and reloading & changing text box values in frmMain?.
    whats going wrong please.

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

    Re: Closing a Modal form

    Most people don't realize that forms retain property and module level variable values when a form is simply unloaded. In order to reset them you need to set the form to Nothing.

  3. #3

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Closing a Modal form

    with VB6;
    ...........
    no sir i am not clear,
    i tied to check up that whether the form is close / open
    but instead of checking the status my code is loading the form , what's wrong here.

    my form is having one MMcontrol & one timer
    .................
    Public Function FormStatus(frms As Form) As String

    If frms.Visible = True Then
    FormStatus = "open"
    'MsgBox FormStatus giving open
    Else
    FormStatus = "close"
    'MsgBox FormStatus giving me close
    End If
    End Function

  4. #4

  5. #5

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question Re: Closing a Modal form

    with VB6;
    thank u sir,
    i have two goals
    (1) to check whether the form is open / closed
    (2) to unload the instance of the form which is having the
    references FROM the main form
    .....................................
    goal 2

    (a) i wanted to check whether a form is really unloaded or not hence with a command button i used this code

    sub cmd_click()
    ' a command button on the main form
    msgbox forms.count
    end sub

    (b) frmModal is a modal form
    formMain is the main form

    sub frmModal_load() 'here the modal form opens

    1:me.txtMirror.text = formmain.text1.text
    ' i am referencing the main form text box value here
    ' and sum of the timer actions and one multimedia
    ' control ....

    end sub

    Sub frmModal_unload()
    set frmmodal = nothing
    end sub

    'the puzzle starts here by clicking the cmd button after 'closing the frmModal

    if i reference the formmain text box values then
    msgbox 2
    with out reference formmain text box values
    msgbox 1
    how to set it right please
    ..................................................................................
    goal 1

    Public Function FormStatus(frms As Form) As String

    If frms.Visible = True Then
    FormStatus = "open"
    'MsgBox FormStatus
    Else
    FormStatus = "close"
    'MsgBox FormStatus
    End If

    End Function

    'Check this code in immediate window
    ? formstatus(frmModal) ' so i w'nt to know it's open/closed

    'this code is creating a instance of the said form, where as 'just i asked the code to check and give some string values

    help please

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

    Re: Closing a Modal form

    Code:
    Public Function FormStatus(frms As Form) As String
    
    If frms.Visible = True Then 'Your problem is here. This LOADS the form.
        FormStatus = "open"
        'MsgBox FormStatus
    Else
        FormStatus = "close"
        'MsgBox FormStatus
    End If
    
    End Function
    Any time you refer to the form or to a control on the form, the form is loaded.

    Here is an easy way to get around that problem. Put this code in frmModal.

    Code:
    Option Explicit
    Private mLoaded As Boolean
    Private Sub Form_Load()
    
        IsLoaded = True
        
    End Sub
    
    Public Property Get IsLoaded() As Boolean
    
        IsLoaded = mLoaded
        
    End Property
    
    Public Property Let IsLoaded(ByVal bTF As Boolean)
    
        mLoaded = bTF
    
    End Property
    
    Private Sub Form_Unload(Cancel As Integer)
    
        IsLoaded = False
        
    End Sub
    Then in frmMain you can do this:

    Code:
    Private Sub Command1_Click()
    If frmModal.IsLoaded Then
        MsgBox "frmModal is loaded"
    Else
        MsgBox "frmModal is not loaded"
    End If
    End Sub

  7. #7

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Question Re: Closing a Modal form

    thanks i got it ,
    but in my goal2 one doubt is there

    in frmModal unload event i used

    set frmModal = nothing

    is this line not releasing the references to other controls i used!
    if it is a absolute need to reference a value from other controls then how to do it please

  8. #8

  9. #9

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Re: Closing a Modal form

    the code i am using with command button

    sub cmdclose_click()
    unload me
    end sub
    ..................
    sub form_unload()
    set frmModal = nothing
    end sub
    ..............................
    thanks a lot

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

    Re: Closing a Modal form

    You didn't copy/paste that code from your program so I assume that there is more code in those subs that you aren't showing. Please show all the code because what you show should work fine.

  11. #11

    Thread Starter
    PowerPoster make me rain's Avatar
    Join Date
    Sep 2008
    Location
    india/Hubli
    Posts
    2,208

    Lightbulb Re: Closing a Modal form

    this code while the form load sir;
    ...........
    private sub form_load()
    Me.Timer1.Enabled = True
    Me.Timer1.Interval = 1000

    me.txtservicealert.text = formmain.txtSer.text
    me.txtservicealerttime.text = formmain.txtSertime.text

    ' above 2 lines i had eliminated due to the above said problems

    Me.MMControl1.Visible = False
    me.MMControl1.Notify = False
    me.MMControl1.Wait = True
    me.MMControl1.Shareable = False
    me.MMControl1.DeviceType = "Sequencer"
    me.MMControl1.FileName = App.Path & "\alarm.mid"
    me.MMControl1.Wait = True
    me.MMControl1.Command = "Open"

    'Play the sound without waiting.
    me.MMControl1.Command = "Play"
    Exit Sub

    ........................................
    this code i am using with MM control
    Private Sub MMControl1_Done(NotifyCode As Integer)

    ' Close the device.
    MMControl1.Command = "Close"

    ' Open the MCI device.
    MMControl1.Wait = True
    MMControl1.Command = "Open"

    ' Play the sound without waiting.
    MMControl1.Command = "Play"

    End Sub
    ...............................
    this code i am using just for graphical effect
    Private Sub Timer1_Timer()
    If Me.Label1.ForeColor = vbGreen Then
    Me.Label1.Font.Size = 20
    Me.Label1.ForeColor = vbWhite
    Me.Label1.Width = 4932
    ElseIf Me.Label1.ForeColor = vbWhite Then
    Me.Label1.Font.Size = 15
    Me.Label1.ForeColor = vbGreen
    Me.Label1.Width = 2500
    End If

    End Sub
    .....................................
    closing the form
    Private Sub Form_Unload(Cancel As Integer)


    MMControl1.Wait = false
    me.timer1.enabled = false
    me.MMcontrol1.command = "stop"
    unload me
    Set frmAlarm = Nothing

    end sub

    ' previously i used one command button just to unload the form but i removed it & added the code in the the form unload event

    End Sub

    now my program working fine may be because i removed the text box values referenced from other forms, as i coded in form load event
    Last edited by make me rain; May 12th, 2009 at 08:28 AM. Reason: bad colors

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

    Re: Closing a Modal form

    I'm glad you resolved your problem. If you want to you can remove the Unload Me line since it's not needed.

    Code:
    Private Sub Form_Unload(Cancel As Integer)
    
    
    MMControl1.Wait = false
    me.timer1.enabled = false
    me.MMcontrol1.command = "stop"
    'unload me - Not needed
    Set frmAlarm = Nothing
    end sub

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