# Read X number lines from text file to variable

**URL:** https://www.finalbuilder.com/forums/t/read-x-number-lines-from-text-file-to-variable/929
**Category:** Discussion
**Created:** [August 12, 2008, 5:00am UTC](https://www.finalbuilder.com/forums/t/read-x-number-lines-from-text-file-to-variable/929 "2008-08-12T05:00:35Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![anotherlab](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@anotherlab](https://www.finalbuilder.com/forums/u/anotherlab)
#### Post date: [August 12, 2008, 5:00am UTC](https://www.finalbuilder.com/forums/t/read-x-number-lines-from-text-file-to-variable/929/1 "2008-08-12T05:00:35Z")

</div>

Is it possible to read only the top 20 or 30 lines from a text file into a variable?&nbsp; As part of a build, I read the version history for the current build in to a variable and then use that variable in an email message.&nbsp; Since this history can get pretty long, I only need to send the top 20 or so lines in the message,&nbsp; Can that be done with the **Read Text File** action?&nbsp; I'm using FB 6.1.0.866

---

<div class="post-metadata">

### Author: ![tate](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@tate](https://www.finalbuilder.com/forums/u/tate)
#### Post date: [August 13, 2008, 4:59am UTC](https://www.finalbuilder.com/forums/t/read-x-number-lines-from-text-file-to-variable/929/2 "2008-08-13T04:59:15Z")

</div>

You can try using the File Contents Iterator action. You’ll have to use some script in the OnAfterEachIteration event to stop after the number of iterations you want, eg.   
  
 if (Action.LineIndex \> 19)   
 {   
 Action.Reset;   
 }

---

<div class="post-metadata">

### Author: ![anotherlab](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@anotherlab](https://www.finalbuilder.com/forums/u/anotherlab)
#### Post date: [August 13, 2008, 7:57am UTC](https://www.finalbuilder.com/forums/t/read-x-number-lines-from-text-file-to-variable/929/3 "2008-08-13T07:57:46Z")

</div>

How would you add each line to a variable and keep the carriage return/line feeds?

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [August 14, 2008, 4:15am UTC](https://www.finalbuilder.com/forums/t/read-x-number-lines-from-text-file-to-variable/929/4 "2008-08-14T04:15:13Z")

</div>

It should by default keep the new line breaks within the variable.

Since you're putting the variable into an e-mail, be aware that a setting in outlook will automatically remove extra line breaks. So it may appear that there are no new lines, but there actualy is. I've had this problem myself.

[http://support.microsoft.com/kb/287816](http://support.microsoft.com/kb/287816)

Otherwise try some new line characters i.e. \n

&nbsp;

---

<div class="post-metadata">

### Author: ![tate](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@tate](https://www.finalbuilder.com/forums/u/tate)
#### Post date: [August 14, 2008, 6:42am UTC](https://www.finalbuilder.com/forums/t/read-x-number-lines-from-text-file-to-variable/929/5 "2008-08-14T06:42:30Z")

</div>

Also when you concatenate strings, you can add a CRLF, eg. MyString = MyString + vbCRLF
