| | | Forum Newbie
       
Group: Forum Members Last Login: 6/17/2009 1:28:19 PM Posts: 1, Visits: 4 |
| Hi A1 forums,
I've got a small issue with a program I'm working on. In a nutshell, the user enters two values, their name and a number. Those values are written to a text file. I want it to then be able to have the user re-enter their name, and have it check for said name in the text file. The code I have so far works...somewhat.
(I apologize for the bad formatting, if there's any way for me to make it a little less Wall-of-Texty I'll be happy to edit my post)
read = File.OpenText("Codes.txt")
name1 = InputBox("Enter your name.", "Name")
namein = read.ReadLine()
If namein.ToUpper <> name1.ToUpper And tf = False Then
namein = read.ReadLine()
MessageBox.Show(namein & " " & pass, "Debug box", MessageBoxButtons.OK)
ElseIf namein.ToUpper = name1.ToUpper Then
pass = CInt(read.ReadLine())
passin = InputBox("Enter your password.", "Enter")
If pass = passin Then
MessageBox.Show("Password Verified.", "Password")
Else
MessageBox.Show("Password Incorrect, please try again.", "Password Error.", MessageBoxButtons.OK)
End If
MessageBox.Show(namein & " " & pass, "Debug box", MessageBoxButtons.OK)
End If
For the sake of an argument "Codes.txt" contains the following line of text:
Bob, 12.5
My main issue is separating the "Bob" and "12.5" as right now the code is bringing the entire line in as a variable (line in bold). Is there any way for me to separate the name and the code? Thanks a ton for any help that you can give |
| | | | Forum Member
       
Group: Forum Members Last Login: 10/16/2009 10:14:44 AM Posts: 38, Visits: 45 |
| | Is the data on each line delimited by a space or comma? How about reading in the entire line and then filter out the number using the .substring and .IndexOf methods? strName = strInput.Substring(0, strInput.IndexOf(",")) 'assuming data separated by comma
|
| | | | 
Forum God
       
Group: Forum Members Last Login: 9/7/2010 12:29:54 PM Posts: 633, Visits: 1,019 |
| | First, the Split() function is great for separating strings at a delimiter. Use this when you're assigning the ReadLine() value to namein Also, you'll only read the top line of your text file. You'll want to use a loop like this: Do Until EOF(1) Read... Loop "1" would be the integer you assign to a file using the FileOpen function, which in your case I would advise you use. Lastly, for formatting, use Mark's tool. Most A1 gods and gurus do: http://www.a1vbcode.com/a1vbcode/vbforums/Attachment30.aspx
-Mobius |
| |
|
|