Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic ( VB ) (http://www.go4expert.com/forums/visual-basic/)
-   -   code for keeping entered data constant (http://www.go4expert.com/forums/code-keeping-entered-data-constant-t21241/)

viv345 7Mar2010 18:29

code for keeping entered data constant
 
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.

shabbir 7Mar2010 18:38

Re: code for keeping entered data constant
 
Save them to a file and reload the content from file when you run next time.

virxen 7Mar2010 22:06

Re: code for keeping entered data constant
 
or you can use the registry to accomplish that.

shabbir 8Mar2010 10:44

Re: code for keeping entered data constant
 
Quote:

Originally Posted by virxen (Post 65282)
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 10Mar2010 10:20

Re: code for keeping entered data constant
 
How? Any example. Please
Thanks

virxen 10Mar2010 12:47

Re: code for keeping entered data constant
 
Quote:

Originally Posted by viv345 (Post 65427)
How? Any example. Please
Thanks

first of all name your vb version
for example vb6 , vb2008

viv345 11Mar2010 10:11

Re: code for keeping entered data constant
 
In VB6

virxen 12Mar2010 16:24

Re: code for keeping entered data constant
 
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 13Mar2010 15:04

Re: code for keeping entered data constant
 
1 Attachment(s)
Tried:
Given : filepath = App.Path + "\" + filename as C:\Datastore.text
and form 1 with text1.text
BUT IT not worked
Project attached


virxen 14Mar2010 04:37

Re: code for keeping entered data constant
 
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



All times are GMT +5.5. The time now is 05:31.