Reading a Text File's columns (if possible)

A newbie trying to read two columns in a text file has run into some p

Page 1 of 1

2 Replies - 2120 Views - Last Post: 17 June 2009 - 04:13 PM Rate Topic: -----

#1 Freedfromthereal   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 17-June 09

Reading a Text File's columns (if possible)

Posted 17 June 2009 - 03:28 PM

Hello Dream.In.Code!!

I've got a little project that I've been working on, and I have hit a road block. Essentially my program asks the user for their name and a number, and it stores both values in a text file. However, when retrieving the code from a particular line it cannot separate the number from the person's name. My question to you guys is: will I have to use a new line for every entry, or is there some way to tell my program to differentiate between columns in the code?

Dim namein As String
	Dim pass As Integer
	Dim name1 As String = String.Empty
	Dim password As String = String.Empty
	Dim read As StreamReader
	Dim accum As Integer = 0
	Dim tf As Boolean = False
	Dim passin As Integer = 0

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")
				MessageBox.Show("Password Incorrect, please try again.", "Password Error.", MessageBoxButtons.OK)
			End If
			MessageBox.Show(namein & " " & pass, "Debug box", MessageBoxButtons.OK)
		End If

		pass = CInt(read.ReadLine())

		MessageBox.Show(namein & " " & pass, "Debug box", MessageBoxButtons.OK)

I'm coding in VB 2008.NET, and I couldn't get the tutorial on inputting code to work (I believe it's for VB6, which could be the issue)

Any help that I could get on my code would be great, I've been staring at this and a workbook for quite a while and nothing's clicking, thanks in advance smile.gif

Is This A Good Question/Topic? 0
  • +

Replies To: Reading a Text File's columns (if possible)

#2 vbnet9   User is offline

  • D.I.C Regular

Reputation: 12
  • View blog
  • Posts: 366
  • Joined: 26-May 09

Re: Reading a Text File's columns (if possible)

Posted 17 June 2009 - 03:38 PM

		Dim objReader As StreamReader


			objReader = New StreamReader("codes.txt")

			Lines = objReader.ReadLine()

			For A = 0 To Lines

				LArray(A) = objReader.ReadLine()




			'MsgBox("Can't read file")

		End Try

To read a file. Use a character like "|" between columns and detect it to be able to separate columns... something a user won't be likely to enter.
Was This Post Helpful? 1
  • +
  • -

#3 AdamSpeight2008   User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: Reading a Text File's columns (if possible)

Posted 17 June 2009 - 04:13 PM

Have a look at TextFieldParser Tutorial
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1