Solved

Check anything changed

Posted on 1998-10-27
15
227 Views
Last Modified: 2010-04-30
Any good idea:

An application (VB5) holds some data. Users may change them in run time.
I want to check if anything is changed when the users exit the application.
I don't like to put every thing in memory when uers start the application.......

Thank you in advance.
0
Comment
Question by:zhuhail
  • 6
  • 5
  • 3
  • +1
15 Comments
 
LVL 18

Expert Comment

by:deighton
Comment Utility
I assume you mean the data is held in controls on your form e.g. text boxes.

You could write the contents of each control to a text file using write #1.  create the text file in your temp directory.  When the user exits you could retrieve the values from the file using read #1,   etc and compare the new values to th old?
0
 
LVL 1

Accepted Solution

by:
sdbanks earned 120 total points
Comment Utility
Create a form level variable.  In any of your forms values are changed, set the value of this variable to true.  In the form unload query event, check the value of this variable.  If it is true, then something has been changed and you can ask the user if they want to save the changes, ignore the changes, or cancel the form unload.  


0
 

Expert Comment

by:NeuralNick
Comment Utility
The following assumes that your data is loaded into
text boxes, masked ed boxes or combo boxes in a form
called frmMyForm.
Put this code in the click event for a close / exit button
on the form.  It will set blnSomethingChanged to True
if the user has changed something in one of the fields.

Dim objLocalObject As Object
Dim blnSomethingChanged As Boolean
 
        blnSomethingChanged = False
        For Each objLocalObject In frmMyForm
            If (TypeOf objLocalObject Is TextBox) Or (TypeOf _ objLocalObject Is MaskEdBox) Or (TypeOf objLocalObject Is DBCombo) Then
               
                If objLocalObject.DataChanged Then
                    blnSomethingChanged = True

                End If ' LocalObject.DataChanged
            End If ' TypeOf LocalObject
        Next

        If blnSomethingChanged Then

           ' code whatever you want
           ' to happen if some data has changed here

        End If


   

0
 
LVL 1

Expert Comment

by:sdbanks
Comment Utility
I like the way NeuralNick  determines if the value in the controls are changed.  I would not put the code in the click event of a command button though.  A better option would be to put it in the forms QUERYUNLOAD event.  That way if the user closes the form using something other then then command button...ie the X button on the form, it will still be executed.



Steven
0
 

Author Comment

by:zhuhail
Comment Utility
Hi experts

Thank you very much for your answers and comments.
I like the ideas:
1. .ini file (deighton)
2. DataChanged property (NeuralNick)
3. QUERYUNLOAD event (sdbanks)
and in my case, I will use all of the above ideas!

BTW, the END statement may not fire the QueryUnLoad event although END causes the form unloading. Strange?
0
 
LVL 18

Expert Comment

by:deighton
Comment Utility
With End try making a simple form with two command buttons.  button1 is unload me, button2 is End.  

Put a msgbox in your unload code.  button1 displays the msgbox, button2 doesn't.

End is an immediate end to the program.  does close files I believe.
0
 

Author Comment

by:zhuhail
Comment Utility
Hi deighton

I beleive that the test you suggested will be correct.
Do you try to show me that END doesn't fire QueryUnLoad event? However, END should do unloading the form before ending the program....am I write? If END does unloading the form, why not fire QueryUnLoad event?

Cheers
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 18

Expert Comment

by:deighton
Comment Utility
End stops the program running immediately, no more code is executed. If you use an End  the program will finish and the forms will be unloaded, but you won't get any queryunload, terminate or unload event code run.  

Some programmers oppose the use of the end command in VB.  It is a legacy of the original implementation of BASIC.
0
 
LVL 1

Expert Comment

by:sdbanks
Comment Utility
I do not use END anymore as it does not clean up memoryin vbs COM environment.  I now use the following routine:

For i = forms.count -1 to 0 step -1
     unload forms(i)
Next
end
0
 

Author Comment

by:zhuhail
Comment Utility
Many thanks to deighton.

To sdbanks:

    I will increase the pointe since the answers are more than I expected.

    Your END routine is quite interesting. Can you tell me
1.  why not use
      For i = 0 to forms.count-1
2. How to close whole program if it includes non-form modules?
 
Cheers.
                                             
 >      For i = forms.count -1 to 0 step -1
 >          unload forms(i)
 >     Next
 >     end
0
 
LVL 1

Expert Comment

by:sdbanks
Comment Utility
In answer to below, no reason not to use yours  as far as I can see, I just started using the other code as I found it on the Net.

>   1.  why not use
>              For i = 0 to forms.count-1
>  

In answer to your second question re:
>   2. How to close whole program if it includes non-form modules?
I never thought about it before.  What I try to do when I am coding is to make sure that anything that I use a Set command for, ie..
       Set m_client = new cClient
I set that variable to nothing at some point.  My personal preference has been:

1. If I Set a variable in a sub-routine, I try to set it to nothing as soon as it is no longer used, usually at the end of a routine.
2.  If a SET statement is used in a class_initialize of a class module, I set it to nothing in the class_terminate event.
3.   If a Set variable is used when a form is loaded, I try to set it to nothing when the form unloads though the forms query_unload event.
4.  I have not been setting local variable and public varaibles to nothing as I believe they do not need this special treatment.

Hope this helps.  Any comments welcome.

Steven
0
 

Author Comment

by:zhuhail
Comment Utility
Hi Steven

Sorry, I didn't make clear for my last quastion.

1. You said you don't use END statement.
2.  If I don't like the user to click the very small cross button.
3.  I need to set a nice button and (in its click event) code something to stop the running of the program.
4.  I may not stop the program by only unloading the forms...especially, if there are some class moduls and standard moduls.

So what to do to stop the program without END?

Cheers.

0
 
LVL 1

Expert Comment

by:sdbanks
Comment Utility


>     1. You said you don't use END statement.

I should have said that I do not use end statement in forms to stop by itself, at the end of my sample close routine, I have an end statement after the forms are unloaded.

>     2.  If I don't like the user to click the very small cross button.
>     3.  I need to set a nice button and (in its click event) code something to stop the
>     running of the program.

This method does not prevent you from providing the end user with a button or menu option to exit the form or program.  As an example,  You provide a quit program button in the main form in your program.  Rather the quiting the program with end,  you put the code "unload me" in the buttons click event.   This will cause the query_unload event on the form to run which  does the actual cleanup for the program.

>     4.  I may not stop the program by only unloading the forms...especially, if there
>    are some class moduls and standard moduls.
>
>     So what to do to stop the program without END?

There is nothing to stop you from putting the SET xxx = Nothing in the a forms query unload event also.  If you do not have any forms, you should still have an exit routine that will do the clean-up of memory.  Then you could use the end statement at the end of it.

0
 

Author Comment

by:zhuhail
Comment Utility
I think you have made the things much more clear and I have increased the point.
Did you said, when ending a program
1. you never assign variables (from Dim) to nothing, even the very big arrays;
2. you always set the objects (from Set...New..) to nothing

Cheers.
0
 
LVL 1

Expert Comment

by:sdbanks
Comment Utility
I am not sure about the dim staement part of your response.  You might want to check documentation to see if they should be Set to nothing when they are no longer used.

Steven
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now