How can i keep my data constant after quitting from program. For example:- If i have entered Potato in any text box. when quit and reopen the program the word potato remains their.
I don't think that is a good idea and any application specific data should be stored in registry and not user specific data of what he enters. Just semantics.
with the file method ================== you need a form with a textbox named text1 Code: [COLOR=Blue]Option Explicit[/COLOR] Dim filename As String Dim filepath As String Dim text As String [COLOR=Blue]Private Sub Form_Load()[COLOR=Red]'[/COLOR][/COLOR][COLOR=Red]when you load form ,checks if the file exists and reads data[/COLOR] and stores to text var. and textbox1 filename = "datastore.txt" filepath = App.Path + "\" + filename Dim f As Integer f = FreeFile If Dir(filepath) = filename Then Open filepath For Input As #f Line Input #f, text Text1.text = text Close #f End If [COLOR=Blue]End Sub[/COLOR] [COLOR=Blue]Private Sub Form_Terminate()[/COLOR][COLOR=Red]'when the form terminates,exits-->save text to file[/COLOR] Dim f As Integer f = FreeFile Open filepath For Output As #f Print #f, text Close #f [COLOR=Blue]End Sub[/COLOR] [COLOR=Blue]Private Sub Text1_Change()[/COLOR][COLOR=Red]'when you alter text save it to text variable[/COLOR] text = Text1.text [COLOR=Blue]End Sub[/COLOR]
Tried: Given : filepath = App.Path + "\" + filename as C:\Datastore.text and form 1 with text1.text BUT IT not worked Project attached
the program works great when you press X to close your form. I never told you anything about a command button. If you want to end your program with a command button then before "end" copy paste the form_terminate() code like the code below Code: Private Sub [COLOR=Blue]Command1_Click()[/COLOR] [COLOR=Red]Dim f As Integer f = FreeFile Open filepath For Output As #f Print #f, text Close #f[/COLOR] [COLOR=Blue]End End Sub[/COLOR]
Thanks it is working But if i like to delete or clear the text from text1.text, will the procedure will be same as command1_Click() is given?