-
1 Attachment(s)
[RESOLVED] Text edit
Hi all , I'd like to know how edit an spefic value from a text file i.g.
lets supposing that green text is the text file:
how to edit blah blah blah
and blah blah blah
Character = {
name = "Eddie"
skill = "5.3.7.4"
}
Character = {
name = "fergie"
skill = "7.2.5.4"
}
and restoftext blah blah
blah 75 532 4 56
Now What I wanna it's edit every character from text file
something like I click next than next character stats
some like that : Attachment 111283
But I don't know how to select the status from character to textbox
I just know how to read the text :S
if u know how to please help.
-
Re: Text edit
i'd use a class and a list(of that class)
Code:
Public Class character
Public Sub New(ByVal name As String, ByVal skill() As Integer)
Me.name = name
Me.speed = skill(0)
Me.agility = skill(1)
Me.creativity = skill(2)
Me.practice = skill(3)
End Sub
Private _name As String
Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Private _speed As Integer
Public Property speed() As Integer
Get
Return _speed
End Get
Set(ByVal value As Integer)
_speed = value
End Set
End Property
Private _agility As Integer
Public Property agility() As Integer
Get
Return _agility
End Get
Set(ByVal value As Integer)
_agility = value
End Set
End Property
Private _creativity As Integer
Public Property creativity() As Integer
Get
Return _creativity
End Get
Set(ByVal value As Integer)
_creativity = value
End Set
End Property
Private _practice As Integer
Public Property practice() As Integer
Get
Return _practice
End Get
Set(ByVal value As Integer)
_practice = value
End Set
End Property
Public Function toStringArray() As String()
Return New String() {"Character = {", "name = " & Me.name, String.Format("skill = ""{0}.{1}.{2}.{3}""", Me.speed, Me.agility, Me.creativity, Me.practice), "}"}
End Function
End Class
Code:
Public Class Form1
Dim index As Integer = -1
Dim characters As New List(Of character)
Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
'save
Dim newLines As New List(Of String)
For x As Integer = 0 To characters.Count - 1
newLines.AddRange(characters(x).toStringArray)
Next
IO.File.WriteAllLines("filename.txt", newLines.ToArray)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'read file
Dim lines() As String = IO.File.ReadAllLines("C:\Users\Paul\Desktop\characters.txt")
For x As Integer = 1 To lines.GetUpperBound(0) Step 4
characters.Add(New character(lines(x).Split(New String() {"=", """"}, StringSplitOptions.RemoveEmptyEntries).Last, _
Array.ConvertAll(lines(x + 1).Split(New String() {"=", """", " ", "."}, StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray, Function(s) CInt(s))))
Next
Button1.PerformClick()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'next
index += If(index < characters.Count - 1, 1, 0)
showValues()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'previous
index -= If(index > 0, 1, 0)
showValues()
End Sub
Private Sub showValues()
TextBox1.Text = characters(index).name
TextBox2.Text = characters(index).speed.ToString
TextBox3.Text = characters(index).agility.ToString
TextBox4.Text = characters(index).creativity.ToString
TextBox5.Text = characters(index).practice.ToString
End Sub
End Class