473,503 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Searching for a specific word in a text file using VB6

3 New Member
For a school project i am attempting to create a register and login section of a program. i have managed to create the register by writing user names and passwords to a text document, as we cannot use access databases. however in order to do the actual login i have no idea on how to search the text file for a specific password. All my inputs are in text boxes, and i was wondering if anyone could be any help.
Jul 29 '10 #1
4 8322
Guido Geurs
767 Recognized Expert Contributor
Put the text from the file with the name and passwords in an array (total text).
Split each array input (total text) into an second array.
Find in this second array the name and password.

See attachment
Jul 29 '10 #2
LizAmmo
3 New Member
this is my code

Option Explicit
Dim ArrayPassword() As String

Private Sub Form_Load()
Dim FileIn As Integer
Dim inputdata As String
ReDim ArrayPassword(0)
FileIn = FreeFile
On Error GoTo Error_Laden
Open "\\MAM-INET\aimee.burns$\SDD\Year12\project\passwords.txt " For Input As #FileIn
Do While Not EOF(FileIn)
ReDim Preserve ArrayPassword(UBound(ArrayPassword) + 1)
Input #FileIn, inputdata
ArrayPassword(UBound(ArrayPassword)) = inputdata
Loop
Close #FileIn
Exit Sub
Error_Laden:
Close #FileIn
MsgBox ("Error loading !")
End Sub

Private Sub Command1_Click()
Dim ArrPasswordIdx As Integer
Dim ArrayPWLine() As String
Dim Found As Boolean
Found = False
For ArrPasswordIdx = LBound(ArrayPassword) + 1 To UBound(ArrayPassword)
ReDim ArrPwline(0)
ArrayPWLine = Split(ArrayPassword(ArrPasswordIdx), " ")
If ArrayPWLine(0) = txtUsername.Text Then
txtpassword.Text = ArrayPWLine(1)
Found = True
End If
Next
If Found = False Then
txtpassword.Text = ""
MsgBox "Not a valid name"
End If
End Sub

however i keep getting "subscript out of range" errors
the code ive used for writing the username and password to a file is

Private Sub cmdRegister_Click()
Dim EmployeeName As String
EmployeeName = txtUsername
Open "\\MAM-INET\aimee.burns$\SDD\Year12\project\Passwords.txt " For Append As #1
Dim Password As Integer
Password = Int(Rnd * 1000) + 1 'Generate number
MsgBox "Your pass number is" & Password
Print #1, EmployeeName, Password
Close #1
frmmanagelogin.Show
Unload Me
End Sub

Private Sub Form_Load()

End Sub

im using random no. generator cause its part of our program specifications. any idea on how to fix this?
Aug 3 '10 #3
Guido Geurs
767 Recognized Expert Contributor
Your code=

Expand|Select|Wrap|Line Numbers
  1. Print #1, EmployeeName, Password
sets a TAB between name and password while the textline is split with a SPACE=

Expand|Select|Wrap|Line Numbers
  1. ArrayPWLine = Split(ArrayPassword(ArrPasswordIdx), " ")
The TAB as separator gives "subscript out of range" by splitting the line.
It must be:

Expand|Select|Wrap|Line Numbers
  1. Print #1, EmployeeName & " " & Password

If You use RND, You must also initialize the generator with: Randomize (see attachment) (see also help of VB6)

If it still not work on Your PC, please attach Your VB6 project (Zipped) in BYTES.

PS !! I have put some lines in comment !! it's for doing some tests !! Your code is not wrong !!!
Aug 3 '10 #4
LizAmmo
3 New Member
Yay, Success at last. Thankyou,Thankyou,Thankyou,Thankyou,Thankyou,Thank you,
Aug 4 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
3096
by: Simon Verona | last post by:
Not sure if this is the best group... it may be better off in one of the ADO groups, but I'm sure somebody here knows the answer: I'm trying to load up a text file using ADO.net, as follows: ...
2
4466
by: Praveen_db2 | last post by:
Hi all Db2 8.1.3 windows Is there any way to write data into a text file using a stored procedure? The way we return a cursor output to the calling application, can we return data in a text...
1
2176
by: christine0207 | last post by:
Hi, how to generate a fixed length data text file using Scripting.TextStream / filesystemobject.
2
17394
by: asenthil | last post by:
Hai, i'm a beginner to java... just now i had tried to read and write files using java... and then i had tried to connect a database using jdbc... now i want to export the data's from a...
1
2446
by: sai14 | last post by:
Hi all, i would like to know if it is possible find particular string in a text file using vc++? please do let me know how to write the syntax Thanks
1
1683
by: rajap | last post by:
How to write all the links of the google search result page into a text file using C#.
4
7825
by: varsha desai | last post by:
Hello there, I want to change some data(which is in one line only) of text file using VB 6.0. Which is the best method for it? Another question is I want to delete last two, three lines...
1
8776
by: neveen | last post by:
i want to open and read text file using j2me that can run on mobile 6630 then i want to make button called read that when pressed the data inside text display
2
2596
by: charlesbritto | last post by:
A C++ program for counting individual string in a text file using file handling functions., for ex: if the text file contains, am a boy,am studying +2,am from chennai Now the result shoud...
2
3190
by: sajidali | last post by:
i am trying to append a text file using c#. when i executes my application i writes to the text file using more then one functions. i want to append file only during execution of programe. next time...
0
7083
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7328
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7456
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3153
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
379
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.