Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim dh As New DataHolder(2, "data.txt")
MsgBox(dh.Stat(DataHolder.Stats.AC))
End Sub
End Class
Public Class DataHolder
'enum the stats to save time later
Public Enum Stats
Resilience
Might
Alertness
Insight
AC
Hits
Atk
Level
End Enum
Private _MobileName As String
'keep stats in array to save time later
Private _Stat(7) As String
Public Property MobileName() As String
Get
Return _MobileName
End Get
Set(ByVal Value As String)
_MobileName = Value
End Set
End Property
Public Property Stat(ByVal item As Stats) As String
Get
Return _Stat(item)
End Get
Set(ByVal Value As String)
_Stat(item) = Value
End Set
End Property
'pass in id number and filepath
Public Sub Load(ByVal recNum As Integer, ByVal filename As String)
'read the file to string
Dim fs As New FileStream(filename, IO.FileMode.Open)
Dim sr As New StreamReader(fs)
Dim data As String = sr.ReadToEnd()
sr.Close()
'find the id we want
Dim istart As Integer = data.IndexOf(String.Concat(recNum, ":"))
'read the name
Dim ln As String = getLine(istart, data)
MobileName = ln.Substring(2) 'trim id off
Dim cnt As Integer
'get proceeding lines for stats one at a time
For cnt = 0 To 7
istart = istart + ln.Length + 2 'increments position and adds 2 for the newline character
ln = getLine(istart, data)
_Stat(cnt) = ln
Next
End Sub
'gets a complete line
Private Function getLine(ByVal start As Integer, ByVal data As String) As String
Dim istop As Integer = data.IndexOf(ControlChars.NewLine, start)
Return data.Substring(start, istop - start)
End Function
Public Sub New(ByVal recNum As Integer, ByVal filename As String)
Me.Load(recNum, filename)
End Sub
End Class