As I said, the serialization to disk is only one approach, and you can take whichever your desire, but I'm not so sure about the RTB approach, it just seems awkward.
Basically, I would approach as follows. I've provided code where I think its necessary, you fill in the holes and you'll have a good learning experience.
You need to include a few resources:
Imports System.io 'For the file stream
Imports System.Runtime.Serialization.Formatters.Binary 'For the binary formatter :-)
You will need a class to store your users. Notice its marked as Serializable() so that it can be written to a stream (file stream, in our example)
<Serializable()> Public Class clsUsers
Public strUsername As String
Public strPassword As String
End Class
So, we'll be storing our users as instances of the clsUsers object in an arraylist. This list we need to declare as global to our app, so we put it right inside our "Class Form1" definition.
Class Form1
Dim alAllUsers As New ArrayList
Then, when we load the app (Form1_LoaD) we would want to load the data from disk (our users list) that we saved last time we left the app.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myFileStream As New FileStream(Application.StartupPath & "\Users.cfg", FileMode.Open)
Dim myBinaryFormatter As New BinaryFormatter
alAllUsers = DirectCast(myBinaryFormatter.Deserialize(myFileStream), ArrayList)
myFileStream.Close()
myFileStream.Dispose()
myBinaryFormatter = Nothing
End Sub
We also want a user to be able to register, so we have a button for that:
Private Sub btnRegister_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRegister.Click
'Loop through arraylist to check if the user already exists.
Dim myUser As New clsUsers
myUser.strPassword = Me.txtUsername.Text
myUser.strUsername = Me.txtUsername.Text
alAllUsers.Add(myUser)
myUser = Nothing
end Sub
And, of course, we want to save the new arraylist on the way out of the program.
Private Sub Form1_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
'Leaving the program, need to save our new users file.
Dim myFileStream As New FileStream(Application.StartupPath & "\Users.cfg", FileMode.Open) 'Open the file stream...
Dim myBinaryFormatter As New BinaryFormatter 'Initialize the formatter...
myBinaryFormatter.Serialize(myFileStream, alAllUsers) 'Using our formatter, write the alAllUsers to disk.
myFileStream.Close()
myFileStream.Dispose()
myBinaryFormatter = Nothing
End Sub
I know its a lot of code, and likely a bit 'advanced' to what your doing right now, but if you can spend some time studying the method you'll find it an easy to use solution.
Remember, all its really doing is:
Load Program
Load Data From Disk
Allow user to register
Close Program
Write Data to Disk
From here, you could take the array list and check user/pass combinations when someone tries to login, etc. Please feel free to ask more questions, I'd love to have you understand the method here and am more than willing to explain or re-explain parts as necessary. Also, in all that text, please forgive any mistakes, I'll review in a minute to make sure I didn't include anything to confusing.