Reading lines from Multiline Text box.

Help with reading line from a Multiline Text Box to another text box.

Page 1 of 1

1 Replies - 19335 Views - Last Post: 14 July 2008 - 04:33 PM Rate Topic: -----

#1 Hemendra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-July 08

Reading lines from Multiline Text box.

Post icon  Posted 14 July 2008 - 01:11 PM

I am a newbie in VB i would ask if anyone can help me with a code.
1) I have two Multiline Text boxes and i want their output in another Text box.

The catch is i want each line to be read from both the Text boxes and be appended with
"Greatness is" <textbox 1st line should be here>
"Greatness is" <textbox 2nd line should be here>
"Greatness is" <textbox 3rd line should be here>

This is till where i have been able to reack.
==============================
Private Sub Command1_Click()
If Text1.Text = "" And Text2.Text <> "" Then
MsgBox ("First set of Properties Cannot be blank")
ElseIf Text1.Text <> "" And Text2.Text = "" Then
MsgBox ("Second set of Properties cannot be blank")
ElseIf Text1.Text = "" And Text2.Text = "" Then
MsgBox ("Common you cannot be without properties")
ElseIf Text1.Text <> "" And Text2.Text <> "" Then
Text3.Text = "Greatness is:" & Text1.Text _
& vbCrLf & "Greatness is:" & Text2.Text
End If
End Sub
=============================
Now when i enter in the first box
Good
Polite

and in the second
Courage
Honor

I get the output
Greatness is:Good
Polite
Greatness is:Courage
Honor
==============================
another thing is that i cannot select text by using <Cntrl+A>
Any help is welcome.

Is This A Good Question/Topic? 0
  • +

Replies To: Reading lines from Multiline Text box.

#2 Zhalix  Icon User is offline

  • D.I.C Regular

Reputation: 20
  • View blog
  • Posts: 260
  • Joined: 07-May 08

Re: Reading lines from Multiline Text box.

Posted 14 July 2008 - 04:33 PM

First, make sure to next time post your code in the [code ] [ /code] tags. It makes it easier to read.

To make each line be printed with its own "Greatness is:", you can use the replace function:

Private Sub Command1_Click()

	Dim strProperties As String
	
	'First, combine both textbox text's into one string,
	'but put a new line between them to make the replace function work properly
	
	strProperties = Text1.Text & vbNewLine & Text2.Text
	
	
	'Then, we're going to put the first Greatness is: at the beginning
	'Because there's no new line at the very top to be replaced
	
	strProperties = "Greatness is:" & strProperties
	
	'Now we use the replace function
	
	'String = Replace(StringToLookIn, LookFor, ReplaceWith)
	strProperties = Replace(strProperties, vbNewLine, vbNewLine & "Greatness is:")
	
	Text3.Text = strProperties

End Sub



The same code with no comments:
Private Sub Command1_Click()

	Dim strProperties As String
		
	strProperties = Text1.Text & vbNewLine & Text2.Text
	strProperties = "Greatness is:" & strProperties
	strProperties = Replace(strProperties, vbNewLine, vbNewLine & "Greatness is:")
	
	Text3.Text = strProperties

End Sub



I hope it makes sense. Keep in mind this is not the only way to accomplish this.

Here's a link on string functions that will come in handy in the future when you want to do any sort of editing on strings:

http://www.dreaminco...wtopic13107.htm

This post has been edited by Zhalix: 14 July 2008 - 04:51 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1