Posted: Fri Apr 04, 2003 3:12 am Post subject: Easy Visual Basic question......
I am having a problem parsing some text and putting it into a spreadsheet. I have a text box that a user is going to put data in. Sometimes that data in the text box is going to be single line text, sometimes the data is going to span multiple lines. Then when I click a button the text from the text box is supposed to be added to one cell of the spread sheet. It works partially. The text is added to my spreadsheet, but it won't recognize mutiple line input. Every thing is always put in as single line input. Example of what is does
Excel: aaaa bbbbb
I want the excel cell to look identical to the text in Text1. Such as:
I have heard that I could use vbCrLf, but I don't know how to since the text in the text box will never be the same. Is there a way to code it so that each letter is parsed until an "end of line" character is reached then activate vbCrLf? Someone please help me!!!
Here is the code so far.
If (Headertxt2.Enabled = True) Then
Grid1.Cells(3, 1).Value = Headertxt2.Value
Grid1.Cells(3, 1).Font.Size = 12
Grid1.Cells(3, 1).Font.Bold = True
Grid1.Cells(3, 1).Font.Name = CommonDialog1.FontName
Headertxt2.Value = Null
Headertxt2.Enabled = False
Headertxt2.BackColor = 12632256
Posted: Fri Apr 04, 2003 3:46 am Post subject: Re: Easy Visual Basic question......
Is there a way to code it so that each letter is parsed until an "end of line" character is reached then activate vbCrLf?
vbCrLf is the "end of line" character! It's a VB constant denoting both a carriage return and line feed character: the letters stand for "visual basic carriage return line feed".
Use the InStr function to find the position of the first occurrence of the vbCrLf character in your string. Then you can split your string at that position. Repeat this as many times as needed.
Depending on your system, you may need one of the other similar things instead:
MSDN Library wrote:
The following string constants can be used anywhere in your code in place of actual values:
vbCr: Chr(13) - Carriage return
vbCrLf: Chr(13) & Chr(10) - Carriage return–linefeed combination
vbFormFeed: Chr(12) - Form feed; not useful in Microsoft Windows
vbLf: Chr(10) - Line feed
vbNewLine: Chr(13) & Chr(10) or Chr(10) - Platform-specific newline character; whatever is appropriate for the platform
vbNullChar: Chr(0) - Character having the value 0
vbNullString: String having value 0 Not the same as a zero-length string (""); used for calling external procedures
vbTab: Chr(9) - Horizontal tab
vbVerticalTab: Chr(11) - Vertical tab; not useful in Microsoft Windows
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum