Login using a Text File Database in VB6
In this tutorial, we will going to make a program that has a text file database which will be going to use as our database of the program.
Now, let's start this tutorial!
1.Let's start this tutorial by following the following steps in Microsoft Visual Basic 6.0: Open Microsoft Visual Basic 6.0, click Choose Standard EXE, and click Open.
2.Next, add only one Button named cmdOK and labeled it as "OK". Add two textbox named txtUser for inputting the username and txtPass for inputting the password.You must design your interface like this:
3. Open a notepad and on it type:
Save it as Security.txt.
4.Now put this code for your code module. This code is for cmdOK_Click:
- Private Sub cmdOk_Click()
- Open "Security.txt" For Input As #1
- Do Until EOF(1)
- Input #1, user, pass
- If txtUser.Text = user And txtPass.Text = pass Then
- MsgBox "W E L C O M E", vbInformation
- Exit Sub
- End If
- MsgBox "A C C E S S D E N I E D", vbInformation
- Close #1
- End Sub
We have created a syntax for opening our text file named Security.txt and as For Input As #1. The Open Statement here enables input/output (I/O) to a file. The Open statement syntax has these parts: Pathname - string expression that specifies a file name — may include directory or folder, and drive, Mode - keyword specifying the file mode: Append, Binary, Input, Output, or Random. If unspecified, the file is opened for Random access, Access - keyword specifying the operations permitted on the open file: Read, Write, or Read Write. The #1 here in the code means reading of the text file. The we have created an EOF Do Until Loop. EOF returns a value that indicates whether the current record position is after the last record in a Recordset object. Then we make variables user and pass as our input that is equal to the content of the text file to be read. And if it is equal txtUser and txtPass respectively, then it will prompt the user to "Welcome". Otherwise, it will diplay "Access Denied". The close statement here closes the text file at the end of a request and releases resources.
Download the source code and try it! :)
For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.
Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer
Add and Follow me on Facebook: https://www.facebook.com/donzzsky
Visit and like my page on Facebook at: https://www.facebook.com/BermzISware