5 Replies - 3036 Views - Last Post: 03 March 2009 - 10:25 AM Rate Topic: -----

#1 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Reading/writing text files

Posted 03 March 2009 - 09:35 AM

Ok so we are adding to this space blitz or w/e you want to call it and currently i am adding a highscore form.
so i have it so that the user input three initials and presses an enter button. Then it goes into a listbox where the
users initials and game score enter. I then have it transfer to a text file. all this works but i need some code to
run through the text file and arrange them from highest to lowest

heres my current "HighScore" code

i know its going to be a for loop but im a beginner in vb and it would be so much easier in java :D
button1 is the enter button
button2 is the save button that saves to a text file
Imports System.IO
Public Class HighScore
	Dim objStreamWriter As StreamWriter
	Dim objStreamReader As StreamReader
	Dim strLine As String
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		lstHigh.Items.Add(txtEnter.Text & "	 " & Score)
		Button1.Enabled = False
		txtEnter.Enabled = False
	End Sub

	Private Sub txtEnter_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEnter.TextChanged
		If txtEnter.Text.Length = 3 Then
			Button1.Enabled = True
		ElseIf txtEnter.Text.Length <> 3 Then
			Button1.Enabled = False
		End If
	End Sub


	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

		'Pass the file path and the file name to the StreamWriter constructor.
		objStreamWriter = New StreamWriter("C:\Documents and Settings\220010249\Desktop\HighScore.txt")
		objStreamWriter.WriteLine(strLine)
		'Write a line of text.
		objStreamWriter.WriteLine(txtEnter.Text & "	 " & Score)
		'Close the file.
		objStreamWriter.Close()

	End Sub

	Private Sub HighScore_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		'Pass the file path and the file name to the StreamReader constructor.
		objStreamReader = New StreamReader("C:\Documents and Settings\220010249\Desktop\HighScore.txt")

		'Read the first line of text.
		strLine = objStreamReader.ReadLine

		lstHigh.Items.Add(strLine)

		objStreamReader.Close()
	End Sub
End Class


This post has been edited by Jayman: 03 March 2009 - 10:25 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Reading/writing text files

#2 cbrickhouse  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 57
  • Joined: 01-March 09

Re: Reading/writing text files

Posted 03 March 2009 - 09:39 AM

why not just use an access database instead of a text file?
Was This Post Helpful? 0
  • +
  • -

#3 ProGraM  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 150
  • Joined: 28-September 05

Re: Reading/writing text files

Posted 03 March 2009 - 09:42 AM

I don't even know what that is lol im just beggining in vb
Was This Post Helpful? 0
  • +
  • -

#4 cbrickhouse  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 57
  • Joined: 01-March 09

Re: Reading/writing text files

Posted 03 March 2009 - 09:46 AM

Access comes with office. you could make a simple database with one table with high scores, then run a sort of the table and fill your grid or whatever with it. very easy
Was This Post Helpful? 0
  • +
  • -

#5 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Reading/writing text files

Posted 03 March 2009 - 09:47 AM

This is VB.NET code, not VB6. Moved to VB.NET :)
Was This Post Helpful? 0
  • +
  • -

#6 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Reading/writing text files

Posted 03 March 2009 - 10:25 AM

Modified title to be more descriptive of the problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1