Reputation: 11
For my company, we receive our time sheets in the following format
Name:Hours
Name:Hours
Name:Hours
I have the Timesheet.txt loading into the RichTextBox1 fine, but, I want when I click a button to load them into two different textboxes. I want the Names to load into TextBox1 and Hours to load into TextBox2
Then it deletes the line. It will go onto the next line when I click the button again.
Any help?
Upvotes: 0
Views: 364
Reputation: 1321
Simple, but will do:
Dim sInput As String = "Name:10"
Dim sSplitArray() As String = sInput.Split(New Char() {":"c})
Dim sName As String = sSplitArray(0)
Dim sHours As String = sSplitArray(1)
String's Split function splits a string up by the character you pass to it.
So if you have this:
sInput = "Name:10:Zebra:Kazaam"
When you split that string by the ":" separator, it will give you an array with:
Name
10
Zebra
Kazaam
Upvotes: 1
Reputation: 1326
Hope that this will give the complete solution for your problem
Dim x, y As Integer
Dim textbox1() As TextBox
x = 430
y = 265
Dim str As String
Dim result(), output(1) As String'str=RitchText1.text 'load input string to str
result = str.Split(System.Environment.NewLine) ' split into array based on new line
For i As Integer = 0 To result.Length - 1 'execute up to array limit
output = result(i).Split(":") 'split again based on :
textbox1(i).Text = output(0) 'Name part into dynamic textbox 1
textbox1(i).Location = New Point(x, y)
textbox1(i + 1).Text = output(1) 'Name part into dynamic textbox 2
textbox1(i + 1).Location = New Point(x + 40, y)
Me.Controls.Add(textbox1(i))
textbox1(i).Visible = True
Me.Controls.Add(textbox1(i + 1))
textbox1(i + 1).Visible = True
y = y + 20
Next
Upvotes: 0