emi_sastra
asked on
SEPARATE MULTILINE TEXTBOX TO SEVERAL LABELS
Hi All,
I have a multiline textbox.
How could I separate the contains (separate by vbcrlf) to several labels ?
Let's say it has fixed 4 lines and four labels.
Thank you.
I have a multiline textbox.
How could I separate the contains (separate by vbcrlf) to several labels ?
Let's say it has fixed 4 lines and four labels.
Thank you.
ASKER
Hi HawyLem,
There are several labels.
My problem is how to code to store to those labels.
For example : Address1, Address2, Address3, Address4
Thank you.
There are several labels.
My problem is how to code to store to those labels.
For example : Address1, Address2, Address3, Address4
Thank you.
If you have always 4 labels you could hardcode their names (as i've understood i suppose)
you can use an integer variable to track the line you are reading and then write each line in the appropriate label.
Or maybe I misunderstood your needs?
you can use an integer variable to track the line you are reading and then write each line in the appropriate label.
Or maybe I misunderstood your needs?
ASKER
I want to know a smart way to code it.
Using counter and select case to do it is easy.
Thank you.
Using counter and select case to do it is easy.
Thank you.
For a 4 variables assignment in a managed language I suppose you don't even need any particular code optimization and can have it coded the way you prefer
I don't get it, are you searching for something in particular?
I don't get it, are you searching for something in particular?
ASKER
I wonder I could get like below code.
lblAddress1.text = GetLineData(txtData, 1)
lblAddress2.text = GetLineData(txtData, 2)
lblAddress3.text = GetLineData(txtData, 3)
lblAddress4.text = GetLineData(txtData, 4)
Thank you.
lblAddress1.text = GetLineData(txtData, 1)
lblAddress2.text = GetLineData(txtData, 2)
lblAddress3.text = GetLineData(txtData, 3)
lblAddress4.text = GetLineData(txtData, 4)
Thank you.
You just need a bit of refactoring.
Declare a GetLineData function and pass it two parameters (or just the line number). Make it return the text you chose.
Use a counter integer inside the function to reach the iteration you need to read the line
Declare a GetLineData function and pass it two parameters (or just the line number). Make it return the text you chose.
Use a counter integer inside the function to reach the iteration you need to read the line
ASKER
What is below code do ?
Dim reader As TextReader = New StringReader(TextBox1.Text )
Thank you.
Dim reader As TextReader = New StringReader(TextBox1.Text
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The code
Dim reader As TextReader = New StringReader(TextBox1.Text )
declare a reader variable as a textreader, a character sequential reader
http://msdn.microsoft.com/en-us/library/system.io.textreader(v=vs.80).aspx
and then initialize it as a new stringreader because TextReader is an abstract base class for StringReader
You need a bit of object oriented programming to understand abstract classes and their implementations. The extreme case is an interface and its implementation (all methods are abstract)
Dim reader As TextReader = New StringReader(TextBox1.Text
declare a reader variable as a textreader, a character sequential reader
http://msdn.microsoft.com/en-us/library/system.io.textreader(v=vs.80).aspx
and then initialize it as a new stringreader because TextReader is an abstract base class for StringReader
You need a bit of object oriented programming to understand abstract classes and their implementations. The extreme case is an interface and its implementation (all methods are abstract)
ASKER
Yes, I want a bit OOP programming.
Would please provide the function GetLineData code in OOP way or a recursive way to do it ?
Thank you.
Would please provide the function GetLineData code in OOP way or a recursive way to do it ?
Thank you.
._.
Sorry I didn't get it..
if you mean creating a class or module for just one function I need to advice it's strongly a programming bad practice. Classes should be created to handle more than just one method, otherwise will only be a massive and useless wrapping (generating mess in the code)
I suggest you to use the function "as is", that is the best way to achieve code clearness.
Don't mind OOP, you're already using it :D
if you mean creating a class or module for just one function I need to advice it's strongly a programming bad practice. Classes should be created to handle more than just one method, otherwise will only be a massive and useless wrapping (generating mess in the code)
I suggest you to use the function "as is", that is the best way to achieve code clearness.
Don't mind OOP, you're already using it :D
ASKER
Yes, it works.
Thank you very much for your help.
Thank you very much for your help.
Your welcome :)
Try something like this:
Private Sub txtData_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtData.TextChanged
Dim ctls() As Control
For i As Integer = 0 To txtData.Lines.Length - 1
ctls = Me.Controls.Find("lblAddress" & (i + 1), True)
If ctls.Length > 0 Then
ctls(0).Text = txtData.Lines(i)
End If
Next
End Sub
ASKER
Hi Idle_Mind,
Thank you very much for your code.
Thank you very much for your code.
Open in new window