code for keeping entered data constant

Contributor
7Mar2010,18:29   #1
viv345's Avatar
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.
Go4Expert Founder
7Mar2010,18:38   #2
shabbir's Avatar
Save them to a file and reload the content from file when you run next time.
viv345 like this
Pro contributor
7Mar2010,22:06   #3
virxen's Avatar
or you can use the registry to accomplish that.
viv345 like this
Go4Expert Founder
8Mar2010,10:44   #4
shabbir's Avatar
Quote:
Originally Posted by virxen View Post
or you can use the registry to accomplish that.
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.
viv345 like this
Contributor
10Mar2010,10:20   #5
viv345's Avatar
How? Any example. Please
Thanks
Pro contributor
10Mar2010,12:47   #6
virxen's Avatar
Quote:
Originally Posted by viv345 View Post
How? Any example. Please
Thanks
first of all name your vb version
for example vb6 , vb2008
viv345 like this
Contributor
11Mar2010,10:11   #7
viv345's Avatar
In VB6
Pro contributor
12Mar2010,16:24   #8
virxen's Avatar
with the file method
==================
you need a form with a textbox named text1

Code:
Option Explicit
Dim filename As String
Dim filepath As String
Dim text As String

Private Sub Form_Load()'when you load form ,checks if the file exists and reads data 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
End Sub

Private Sub Form_Terminate()'when the form terminates,exits-->save text to file
Dim f As Integer
f = FreeFile
Open filepath For Output As #f
Print #f, text
Close #f
End Sub

Private Sub Text1_Change()'when you alter text save it to text variable
text = Text1.text
End Sub
viv345 like this
Contributor
13Mar2010,15:04   #9
viv345's Avatar
Tried:
Given : filepath = App.Path + "\" + filename as C:\Datastore.text
and form 1 with text1.text
BUT IT not worked
Project attached

Attached Files
File Type: zip Project1.zip (1.4 KB, 4 views)
Pro contributor
14Mar2010,04:37   #10
virxen's Avatar
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 Command1_Click()
Dim f As Integer
f = FreeFile
Open filepath For Output As #f
Print #f, text
Close #f
End
End Sub