[SIZE=2][COLOR=#0000ff]
Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] btnSave_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] btnSave.Click
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] inpName.Text = "New Character" [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]MsgBox("Please type a name for your character.")
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] startstatsRemaining >= 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]charName = inpName.Text
savefileName = Application.StartupPath & "\Characters\" & charName & ".lfr"
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] fs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] FileStream(savefileName, FileMode.Create, FileAccess.Write)
[/SIZE][SIZE=2][COLOR=#008000]'declaring a FileStream and creating a word document file named file with
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'access mode of writing
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] s [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] StreamWriter(fs)
[/SIZE][SIZE=2][COLOR=#008000]'creating a new StreamWriter and passing the filestream object fs as argument
[/COLOR][/SIZE][SIZE=2]s.BaseStream.Seek(0, SeekOrigin.End)
[/SIZE][SIZE=2][COLOR=#008000]'the seek method is used to move the cursor to next position to avoid text to be
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'overwritten
[/COLOR][/SIZE][SIZE=2]s.WriteLine(charName)
s.WriteLine(attackStat)
s.WriteLine(defenseStat)
s.WriteLine(healthStat)
s.WriteLine(manaStat)
s.WriteLine(powerStat)
s.WriteLine(speedStat)
[/SIZE][SIZE=2][COLOR=#008000]'writing text to the newly created file
[/COLOR][/SIZE][SIZE=2]s.Close()
charName = inpName.Text
CharFile.Add(".\characters\" & charName & ".lfr")
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strm [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IO.FileStream(Application.StartupPath & "\" & "characters.ini", IO.FileMode.OpenOrCreate)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] BinFormatter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Serialization.Formatters.Binary.BinaryFormatter
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] f [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IO.FileInfo(Application.StartupPath & "\" & "characters.ini")
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] f.Length > 1 = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]charNameArray = [/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2](BinFormatter.Deserialize(strm), ArrayList)
CharFile = [/SIZE][SIZE=2][COLOR=#0000ff]DirectCast[/COLOR][/SIZE][SIZE=2](BinFormatter.Deserialize(strm), ArrayList)
charNameArray.Add(inpName.Text)
CharFile.Add(".\characters\" & charName & ".lfr")
BinFormatter.Serialize(strm, charNameArray)
BinFormatter.Serialize(strm, CharFile)
strm.Flush()
strm.Close()
MsgBox("Your character has been created and saved.")
[/SIZE][SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE][SIZE=2] : MsgBox("You have spent to many statistic points.")
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]ElseIf[/COLOR][/SIZE][SIZE=2] startstatsRemaining >= 0 [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strm [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] IO.FileStream(Application.StartupPath & "\" & "characters.ini", IO.FileMode.OpenOrCreate)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] BinFormatter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Serialization.Formatters.Binary.BinaryFormatter
charNameArray.Add(inpName.Text)
CharFile.Add(".\characters\" & charName & ".lfr")
BinFormatter.Serialize(strm, charNameArray)
BinFormatter.Serialize(strm, CharFile)
strm.Flush()
strm.Close()
MsgBox("Your character has been created and saved.")
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]