borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (select..case..true)Next Topic (Regarding Registry and Visual Basic) New Topic New Poll Post Reply
AndreaVB Forum : Frequently Asked Questions : what form on the screen
Poster Message
shahidmojid
Level: Professor

Registered: 09-05-2002
Posts: 85

icon 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
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon 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
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
shahidmojid
Level: Professor

Registered: 09-05-2002
Posts: 85
icon Re: what form on the screen

Thanks JL.

Shahid

13-03-2003 at 09:34 PM
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon 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
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
vbgen
Level: Moderator

Registered: 10-10-2002
Posts: 876
icon Re: what form on the screen

just an add-on...

you could use another form to manage these things, you know, unless you're already using an mdi form.

like JL said, if the coding is done an used inside a form that is affected, then might as well use another form to do all of this, like a monitorign form, which can be hidden and active at the same time, so that coding can be cleaner, since you can set reference back and to this form from the others.

hope this data can be useful to you too.  

____________________________
Been busy trying to take a second degree <--it's not working out...

14-03-2003 at 04:59 PM
View Profile Send Email to User Show All Posts | Quote Reply
shahidmojid
Level: Professor

Registered: 09-05-2002
Posts: 85
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon 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
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: what form on the screen

Can't he just do this (below)? I haven't tested this.

If frmDisplay.visible=true then
  Showdata
Else
   Msgbox &#8220;&#8230;&#8230;&#8230;.&#8221;
End if


____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

03-04-2003 at 05:46 AM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
JLRodgers
Level: Moderator

Registered: 04-04-2002
Posts: 1617
icon 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
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
win_dir
Level: VB Guru

Registered: 04-08-2002
Posts: 390
icon Re: what form on the screen

I was assuming tha he meant a non-MDI enabled form, because he did not say otherwise

____________________________
We have a Mustek 5 M/Pix GSm@rt USB Digital Camera
for just £74.03 , offer only on until 30th February!

<AllDuck.com>      

Enquiries/Sales: 0845 430 9862
Fax: 0870 950 4532

03-04-2003 at 05:13 PM
View Profile Send Email to User Show All Posts Visit Homepage | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: what form on the screen

Hi
This is a really late post, but JL is correct ,calling any public property on a form causes VB to load it into ram (anyone else remember the old "Load myform" command?), MS kept it in but hid it.
Just FYI
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

24-09-2005 at 02:56 AM
View Profile Send Email to User Show All Posts | Quote Reply
shahidmojid
Level: Professor

Registered: 09-05-2002
Posts: 85
icon 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
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Frequently Asked Questions : what form on the screen
Previous Topic (select..case..true)Next Topic (Regarding Registry and Visual Basic) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder