|
-
Dec 20th, 2005, 12:26 PM
#1
Thread Starter
Fanatic Member
Text File For Storing Stats
Hello All,
I'm developing a new application which is going to be used to store statistics based on the button which is pushed. Essentially, the program is going to have 5 buttons (A-E) and there will also be a text box at the bottom for entering a number (default is 1).
When the user presses a button, I'd like the program to store the number into a text document.
There will be one file for each day and in the file, it will say something like this (by default):
[A] = 0
[B] = 0
[C] = 0
[D] = 0
[E] = 0
If the user presses the A button, then I'd like my program to open the txt file, and add the number in TextBox to the value in the text file. If C is pressed, it'll add that number to the C value in the text document. (Following me?)
Can anyone help me with some syntax on how this would be done, while preserving the text box structure? (No extra line breaks, anything like that) I guess I need help building code to search the textbox, pull out the value from the correct line (A-E depending on the button), then adding that value to a (integer) which is the value from the text box in the program, and then store that value back onto the correct line in the text file.
I think this may sound harder than it actually is going to be... but I'm still a very much newbie when it comes to reading and writing to text files.
Thanks in advance!
-
Dec 20th, 2005, 12:45 PM
#2
Re: Text File For Storing Stats
This should at least get you started
VB Code:
Option Explicit
Private strLine As String
Private arrLine() As String
Private Sub cmdA_Click()
Do While Not EOF(1)
Line Input #1, strLine
If InStr(1, strLine, "[A]") Then
arrLine = Split(strLine, " ")
MsgBox Val(arrLine(2)) + Val(Text1.Text)
Exit Do
End If
Loop
End Sub
Private Sub cmdB_Click()
Do While Not EOF(1)
Line Input #1, strLine
If InStr(1, strLine, "[B]") Then
arrLine = Split(strLine, " ")
MsgBox Val(arrLine(2)) + Val(Text1.Text)
Exit Do
End If
Loop
End Sub
Private Sub cmdC_Click()
Do While Not EOF(1)
Line Input #1, strLine
If InStr(1, strLine, "[C]") Then
arrLine = Split(strLine, " ")
MsgBox Val(arrLine(2)) + Val(Text1.Text)
Exit Do
End If
Loop
End Sub
Private Sub cmdD_Click()
Do While Not EOF(1)
Line Input #1, strLine
If InStr(1, strLine, "[D]") Then
arrLine = Split(strLine, " ")
MsgBox Val(arrLine(2)) + Val(Text1.Text)
Exit Do
End If
Loop
End Sub
Private Sub cmdE_Click()
Do While Not EOF(1)
Line Input #1, strLine
If InStr(1, strLine, "[E]") Then
arrLine = Split(strLine, " ")
MsgBox Val(arrLine(2)) + Val(Text1.Text)
Exit Do
End If
Loop
End Sub
Private Sub Form_Load()
Open "d:\mateo107.txt" For Input As #1
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Close #1
End Sub
The contents of d:\mateo107.txt is:
Code:
[A] = 1
[B] = 2
[C] = 3
[D] = 4
[E] = 5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|