Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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?
Posted
Updated 18-May-20 2:47am
Comments
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)
file.WriteLine(value)
file.Close()
Else
Dim file As New System.IO.StreamWriter(path, True)


File.WriteLine(header)
File.WriteLine(value)
File.Close()
End If
I want to auto increment my hitCount by 1.

1 solution

Add

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.
 
Share this answer
 
Comments
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900