 |
shahidmojid Level: Professor
 Registered: 09-05-2002 Posts: 85
|
what form on the screen
How can I know that my desired form showing on the screen?
What I want to know is -
My Form is: frmDisplay
If displaying__frmDisplay then 'what coding
Showdata
Else
Msgbox “……….”
End if
Can someone help me please
|
|
12-03-2003 at 11:04 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1658
|
Re: what form on the screen
You could always have a FormNameVisible Variable (Boolean) on every form, set to True in Form_Load, and False in Form_QueryUnload.
____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)
|
|
12-03-2003 at 11:10 PM |
|
|
shahidmojid Level: Professor
 Registered: 09-05-2002 Posts: 85
|
Re: what form on the screen
Thanks JL.
Shahid
|
|
13-03-2003 at 09:34 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1658
|
Re: what form on the screen
Forgot to say this, but I'm sure you know, or will find out soon, the variable has to be Public to ALL of the program (so put it in a module). If it's in the form, it will be unloaded with the form, and trying to reference it will either 1)error, or 2)reload the form.
____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)
|
|
13-03-2003 at 10:04 PM |
|
|
shahidmojid Level: Professor
 Registered: 09-05-2002 Posts: 85
|
Re: what form on the screen
Thanks Gen...,
I have done it already as JL said. Well, your idea also pretty. Thanks for help.
|
|
14-03-2003 at 06:17 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1658
|
Re: what form on the screen
Since this is a popular/common topic, I moved it here.
Below is another way of doing it, not resulting to setting variables to true/false. Haven't tested it without a MDI form, but I haven't written many programs that don't use one.
As my other posts, this way is more complex, but allows for expansion. As a note, the "For each" loop in the IsFormVisible is the only thing really required to check for a form being visible.
The way below has one location where the formnames are stored, this way if you do numerous checks, you just need to know what form you're looking for, and not the name of the form. (Makes less chance for typing formname errors). Enter the code in a module, and you'll see what I mean.
' In a MODULE
Public Enum eFormNames
FRM_SPLASH
FRM_MAIN
FRM_LOGIN
FRM_ABOUT
FRM_MAXFORMS ' MUST be the last in the list
End Enum
Public Type tFormNames
FormName() As String
End Type
Public AllFormNames As tFormNames
Option Explicit
Private Sub InitForms()
' Call this as soon as the program starts
ReDim AllFormNames.FormName(FRM_MAXFORMS)
With AllFormNames
.FormName(FRM_SPLASH) = "frmSplash"
.FormName(FRM_MAIN) = "frmMain"
.FormName(FRM_LOGIN) = "frmLogin"
.FormName(FRM_ABOUT) = "frm_About"
End With
End Sub
Private Sub DeInitForms()
Erase AllFormNames.FormName
End Sub
Public Function IsFormVisible(ByVal FormName As eFormNames) As Boolean
Dim sSearchFor As String
Dim frm As Form
IsFormVisible = False
sSearchFor = LCase(AllFormNames.FormName(FormName))
For Each frm In Forms
If LCase(frm.Name) = sSearchFor Then
IsVisible = True
End If
Next
Set frm = Nothing
Exit Function
Exit Function:
IsFormVisible = False
End Function
|
[Edited by JLRodgers on 14-03-2003 at 03:21 PM GMT]
____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)
|
|
14-03-2003 at 09:17 PM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1658
|
Re: what form on the screen
By doing that, sometimes it will actually load the form! Well, if it's not loaded, it will load the form. May be just a glitch, but I've had it happen before in programs which lead to some interesting problems.
Edited:
Just checked it, if you have form1 and form2 (neither a MDIChild) you can check with "If form2.visible". If they are MDIChildren, "If form2.visible" will load form2.
[Edited by JLRodgers on 03-04-2003 at 02:19 AM GMT]
____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)
|
|
03-04-2003 at 08:16 AM |
|
|
shahidmojid Level: Professor
 Registered: 09-05-2002 Posts: 85
|
Re: what form on the screen
Thanks a lot for your reply. Actually this post reminded me about this forum. I was bit away from here.
Thank you once again for your reply and i will be here regulary.
SM
|
|
24-09-2005 at 08:43 AM |
|
|
|
|
 |
 |