For this you will need a standard form, two text boxes and two buttons. You will also need a text file.
First thing you need to do is to create the form with the text boxes and buttons. Under the first button we will put the code to get the data from the text file and to put it into the first text box:
Private Sub Command1_Click() 'This will declare the variable data as a string Dim data As String 'This will find the file that we are using Open "\the address\name of file.txt" For Input As #1 Input #1, MyData 'This puts the data in the textbox Text1.Text = MyData Close #1 End Sub
In the text file put a number into the it and save. now when you press F5 and press the first button it should show you the number. Simple now we look at changing the data.
This next part is a bit bigger but what it does is that it will change the data in the text file but not add to it.
Private Sub Command2_Click() Dim data As String Open "\vb\tutorials\datafile.txt" For Input As #1 Input #1, MyData Close #1 Open "\vb\tutorials\datafile.txt" For Output As #1 mydata2 = Val(Text2.Text) + Val(MyData) Print #1, mydata2 myTimeStamp = Now Print #1, "data"; myTimeStamp Close #1 Open "\vb\tutorials\datafile.txt" For Input As #1 Input #1, MyData Close #1 Text2.Text = MyData End Sub
It is similar to the first part but now it will change the data and add the date and time.
If you have any problems then just comment and I will do all that I can to help






MultiQuote






|