Results 1 to 2 of 2

Thread: Text File For Storing Stats

  1. #1

    Thread Starter
    Fanatic Member mateo107's Avatar
    Join Date
    Jan 2005
    Posts
    547

    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!


    -Matthew-

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Text File For Storing Stats

    This should at least get you started
    VB Code:
    1. Option Explicit
    2.  
    3. Private strLine As String
    4. Private arrLine() As String
    5.  
    6. Private Sub cmdA_Click()
    7.   Do While Not EOF(1)
    8.    Line Input #1, strLine
    9.     If InStr(1, strLine, "[A]") Then
    10.      arrLine = Split(strLine, " ")
    11.      MsgBox Val(arrLine(2)) + Val(Text1.Text)
    12.      Exit Do
    13.     End If
    14.   Loop
    15. End Sub
    16.  
    17. Private Sub cmdB_Click()
    18.   Do While Not EOF(1)
    19.    Line Input #1, strLine
    20.     If InStr(1, strLine, "[B]") Then
    21.       arrLine = Split(strLine, " ")
    22.      MsgBox Val(arrLine(2)) + Val(Text1.Text)
    23.      Exit Do
    24.     End If
    25.   Loop
    26. End Sub
    27.  
    28.  
    29. Private Sub cmdC_Click()
    30.  Do While Not EOF(1)
    31.    Line Input #1, strLine
    32.     If InStr(1, strLine, "[C]") Then
    33.       arrLine = Split(strLine, " ")
    34.      MsgBox Val(arrLine(2)) + Val(Text1.Text)
    35.      Exit Do
    36.     End If
    37.   Loop
    38. End Sub
    39.  
    40.  
    41. Private Sub cmdD_Click()
    42.  Do While Not EOF(1)
    43.    Line Input #1, strLine
    44.     If InStr(1, strLine, "[D]") Then
    45.       arrLine = Split(strLine, " ")
    46.      MsgBox Val(arrLine(2)) + Val(Text1.Text)
    47.      Exit Do
    48.     End If
    49.   Loop
    50. End Sub
    51.  
    52.  
    53. Private Sub cmdE_Click()
    54.  Do While Not EOF(1)
    55.    Line Input #1, strLine
    56.     If InStr(1, strLine, "[E]") Then
    57.       arrLine = Split(strLine, " ")
    58.      MsgBox Val(arrLine(2)) + Val(Text1.Text)
    59.      Exit Do
    60.     End If
    61.   Loop
    62. End Sub
    63.  
    64. Private Sub Form_Load()
    65. Open "d:\mateo107.txt" For Input As #1
    66. End Sub
    67.  
    68. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    69. Close #1
    70. 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
  •  



Click Here to Expand Forum to Full Width