Click here to Skip to main content
14,545,210 members
Rate this:
Please Sign up or sign in to vote.
See more:
I'am writing my data to a text file, and I want my id be incremented by 1, so that every time i write a data to a text file the id will increment by 1. can anyone help?
Updated 18-May-20 2:47am
Pheonyx 31-Mar-14 4:41am
How are you writing your text file, you've given no code so we have no idea what you are already doing.
Cuculala 31-Mar-14 4:59am
Here's my code
Public hitcount As Integer = 0
Public email As String = ""
Public pageVisit As String = ""
Public dateTimeVisit As String = ""

Dim header As String = hID.PadRight(5) & "|" & hEmail.PadRight(25) & "|" & hPage.PadRight(50) & "|" & hdateTime.PadRight(15)
Dim value As String = hitcount.ToString.PadRight(5) & " " & email.PadRight(25) & " " & pageVisit.PadRight(50) & " " & dateTimeVisit.PadRight(15)

If System.IO.File.Exists(path) = True Then
Dim file As New System.IO.StreamWriter(path, True)
Dim file As New System.IO.StreamWriter(path, True)

End If
I want to auto increment my hitCount by 1.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1


hitcount += 1

After your End if, then each time you have written to the file it will increase.
However, if this is within a function then your hitcount is going to reset to 0 each time the function is called. As we can't see this based on your code snippet we cannot advise fully.

Also, you should use the "Improve Question" to put the code snippet in your question with the appropriate formatting.
Cuculala 31-Mar-14 6:05am
I'm sorry im new to this forum, thanks for advice I'll improved my question next time
Pheonyx 31-Mar-14 6:06am
No problem, I thought I'd let you know :-) At least you know to use the "Reply" button, so many don't.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100