Click here to Skip to main content
15,914,010 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: probelm on Reading txt file..?? Pin
Steve Pullan20-Mar-06 15:14
Steve Pullan20-Mar-06 15:14 
AnswerRe: probelm on Reading txt file..?? Pin
Guerven20-Mar-06 17:28
Guerven20-Mar-06 17:28 
GeneralRe: probelm on Reading txt file..?? Pin
campbells20-Mar-06 18:54
campbells20-Mar-06 18:54 
GeneralRe: probelm on Reading txt file..?? Pin
Dave Kreskowiak20-Mar-06 19:09
mveDave Kreskowiak20-Mar-06 19:09 
GeneralRe: probelm on Reading txt file..?? Pin
campbells20-Mar-06 19:53
campbells20-Mar-06 19:53 
GeneralRe: probelm on Reading txt file..?? Pin
Dave Kreskowiak21-Mar-06 4:03
mveDave Kreskowiak21-Mar-06 4:03 
GeneralRe: probelm on Reading txt file..?? Pin
campbells21-Mar-06 22:16
campbells21-Mar-06 22:16 
GeneralRe: probelm on Reading txt file..?? Pin
Dave Kreskowiak22-Mar-06 3:37
mveDave Kreskowiak22-Mar-06 3:37 
Nonononono!!! Since you control writing the file, you're doing it in such a way that makes it easy to write but also makes it very tedious to read it back in.

What's up with these Now's?? Since your Format's don't have any parameters, calling Now all the time isn't doing anythis. And using String.Format doesn't benefit you either!
strmw.WriteLine(String.Format("Player:" & x, Now))   '?????????

If I was in your position, I'd be saving all my Player data into a collection of Player objects. Then you can just serialize the collection out to an XML file and read it back in just as easy.
Public Class Player
    Private _PlayerName As String
    Private _Position As Integer    '?  I don't know what data type you're using
    Private _MoveStep As Integer    '?  I don't know what data type you're using
 
    Public Property PlayerName As String
        Get
            Return _PlayerName
        Eng Get
        Set(ByVal value As String)
            _PlayerName = value
        End Set
    End Property
 
    .
    .   ' Same thing for your other Player properties
    .
 
    Public Sub New()
    End Sub
 
    Public Sub New(ByVal playerName As String, ByVal position As Integer, ByVal moveStep As Integer)
        Me.PlayerName = playerName
        Me.Position = position
        Me.MoveStep = moveStep
    End Sub

Then, to maintain a collection of Players, in an appropriate place in your code:
Dim Players() As Player

(This is quik and dirty mind you! I'd actually create another class to maintain the Players collection and put the SaveData and LoadData methods in this class).

Now, to save your Player data, all you need to do is something like this:
Public Sub SavePlayerData()
    Dim sw As New StreamWriter(Path.Combine(Application.StartupPath, "PlayerData.xml"))
    Dim xmls As New XmlSerializer(Players.GetType())
    xmls.Serialize(sw, Players)
    sw.Close()
End Sub

To load that data:
Public Function LoadPlayerData()
    Dim sr As New StreamReader(Path.Combine(Application.StartupPath, "PlayerData.xml"))
    Dim xmls As New XmlSerializer(Players.GetType())
    Players = CType(xmls.Deserialize(sr), Player())

Done! You don't have to do any parsing of lines or data because the Serializer does it all for you!


RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

GeneralRe: probelm on Reading txt file..?? Pin
campbells24-Mar-06 21:46
campbells24-Mar-06 21:46 
GeneralRe: probelm on Reading txt file..?? Pin
Dave Kreskowiak25-Mar-06 2:38
mveDave Kreskowiak25-Mar-06 2:38 
GeneralRe: probelm on Reading txt file..?? Pin
campbells25-Mar-06 5:37
campbells25-Mar-06 5:37 
GeneralRe: probelm on Reading txt file..?? Pin
campbells27-Mar-06 2:11
campbells27-Mar-06 2:11 
GeneralRe: probelm on Reading txt file..?? Pin
Dave Kreskowiak27-Mar-06 17:02
mveDave Kreskowiak27-Mar-06 17:02 
QuestionIP address from TCPClient Pin
Polymorpher20-Mar-06 12:46
Polymorpher20-Mar-06 12:46 
AnswerRe: IP address from TCPClient Pin
Dave Kreskowiak20-Mar-06 19:03
mveDave Kreskowiak20-Mar-06 19:03 
Questiontry/catch block usage Pin
spoodygoon20-Mar-06 11:42
spoodygoon20-Mar-06 11:42 
AnswerRe: try/catch block usage Pin
Steve Pullan20-Mar-06 12:22
Steve Pullan20-Mar-06 12:22 
AnswerRe: try/catch block usage Pin
HimaBindu Vejella20-Mar-06 18:41
HimaBindu Vejella20-Mar-06 18:41 
QuestionModem/Adsl status Pin
FeRtoll20-Mar-06 11:24
FeRtoll20-Mar-06 11:24 
QuestionMemory issue Pin
luciodandrea20-Mar-06 6:49
luciodandrea20-Mar-06 6:49 
AnswerRe: Memory issue Pin
CWIZO20-Mar-06 7:49
CWIZO20-Mar-06 7:49 
AnswerRe: Memory issue Pin
Dave Kreskowiak20-Mar-06 9:37
mveDave Kreskowiak20-Mar-06 9:37 
GeneralRe: Memory issue Pin
luciodandrea21-Mar-06 3:06
luciodandrea21-Mar-06 3:06 
Questionclick button bold Pin
zabsmarty20-Mar-06 5:56
zabsmarty20-Mar-06 5:56 
AnswerRe: click button bold Pin
Roy Heil20-Mar-06 6:34
professionalRoy Heil20-Mar-06 6:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.