hi all
Tell me how can I check if a form is already loaded in the memory.
In my application I have Form ‘Full-n-Final’ calling another form ‘Process-Payroll’. And Form ‘Process-Payroll’ can be called independantly also. I am checking the ‘Full-n-Final’.visible property in activate event of ‘Process-Payroll’
If Iam working on form ‘Full-n-Final’ then it’s fine, but if i call ‘Process-Payroll’, then form ‘Full-n-Final’ is implicitly loaded & displayed b’coz of the check at the time of activation
How do i come out of this.
Thanx/Regards
Karuna
hello,
though your code is working fine, there ia another method, you can try
Dim FrmName As Form
For Each FrmName In Forms
If FrmName.Name = “FRMQUICK” Then
Unload FRMQUICK
Exit Sub
End If
Next FrmName
arti
thanx for the reply
i’ve already done something like that, & it is working fine now
Karuna
Reading your request, I have some idea here. Define a global form-loaded flag, set it to tru at form loading and false at form unloading. Other forms just need to check this flag to know if this form is loaded.
Jonathan
insert a module in a project
define :
Public f1 as boolean
On de form you like to detect:
Private Sub Form_Load()
f1 = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
f1 = False
End Sub
Test f1 to knouw if then form is loaded.
I hope you can work
Hi,
Good programming way is that You never use forms true name.
The way VB 6 works is that forms are loaded when u refer stricktly to it. for example if u try:
if frmCustomer.Visible=True then => Form is defined as globally type inside application by VB itself. VB checks if form is loaded and if it isn’t it loads and checks property and form stays loaded until u unload it.
How to avoid this:
modMain.bas: or whatever module
Global gCustomer as frmCustomer
Usage of frmCustomer inside application.
If gCustomer is Nothing Then
if gCustomer .Visible then
. do something
else
. do something else
end if
end if
When u want to load frmCustomer use it like:
If gCustomer is Nothing Then
set gCustomer = new frmCustomer
gCustomer .Visible=True
gCustomer .Caption = “Only instance”
gCustomer .Show
debug.print gCustomer.Name ’ you’ll see that this is still frmCustomer
End If
To unload frmCustomer
if not gCustomer is nothing then
gCustomer.dosomethingIfNeeded
unload gCustomer
set gCustomer = nothing
end if
Outside of frmCustomer code refer allways
gCustomer.[propertyname]
And intside of frmCustomer code refer allways
Me.[propertyname]
Toby
PS Never use keyword NEW when defining form or class (even it is allowed):
WRONG WAY
dim myClass as New Class1
RIGHT WAY
dim myClass as Class1
set myClass = New Class1
You can check the forms-collection, if the form exists in that collection it is loaded. Otherwise, not.
yes it does check correctly but my problem is that as soon as i refer to the form’s name it is implicitly loaded,even if it previously was not
Karuna
not that simple buddy
i do not want to check for the application’s instance i want to check if a form is already loaded or not b’coz i have to check for a form’s loaded property at the activate event of other. & if it is not already loaded, leave it aside. checking it by visible property loads the form evenif it is not already loaded
Karuna
Try this:
Function IsLoaded(ByVal Frm As Form) As Boolean
Dim f As Form
For Each f In Forms
If f.Name = Frm.Name Then
IsLoaded = True
Exit Function
End If
Next
IsLoaded = False End Function
Hope it helps!
Regards,
JARP
Hi just check forms inside application like…
Dim tFrm As Form
For Each tFrm In Forms
Debug.Print tFrm.Name 'or check whatever Form property You want to.
Next
Toby
In order to have access to the visible property of any window, that window must be an object of some sort of the program referencing it. In other words, if I launch MS-Word via OLE, I can read the visible property or Word. But if Word is launched independently, my program can not see that visible property. If the target program makes a status entry in the registry or some other storage outside the program itself like and INI or Dat file, that can be referenced. But this is not a direct reference to the window’s visible property and, as you might assume, my be subject to error.
Skip
Hi
Just check whether app.previnstance =3D true or not .simple.
Ashutosh
hi
thanx for the reply.But this coding is not working in VB6.
It gives me the error :Variable not defined - SYSCMD_GETOBJECTSTATE
Do i need to add some references
What is this SysCmd function. Can u pls elaborate or any other way out
Karuna
U can use:
Function IsFormLoaded(lstrFormName As String) As Integer
IsFormLoaded = SysCmd(SYSCMD_GETOBJECTSTATE, A_FORM, lstrFormName)
End Function
HTH
The way I have addressed this problem has been to write a status entry in the registry or a file (INI,DAT, ect). I have the program write a “LastStatus” entry. If the application is running, I have it update that status every 5 to 10 seconds. When the program closes properly, or as the result of a controlled error, I have it write “LastStatus” with a value indicating the program has closed.
In the event the app has completely errored out or been terminated by an abrupt system shutdown, the “LastStatus” would so indicate in that the elapsed time would be greater than the established interval. If that condition is true, the assumption would be that it is safe to continue launching the current session.
Skip
This is how it is done in VBA
Function IsFormLoaded(pstrFormName As String) As Integer
IsFormLoaded =3D SysCmd(SYSCMD_GETOBJECTSTATE, A_FORM, pstrFormName)
End Function
Thank You
Kevin Albrecht
Senior Treasury Analyst
Asset Liability Management
Washington Mutual Bank FA