The online community for software testing & quality assurance professionals
 
 
Calendar   Today's Topics
Sponsors:
Lost Password?

Home
BetaSoft
Blogs
Jobs
Training
News
Links
Downloads



Testing Tools >> Micro Focus/Borland/Segue SilkTest

Pages: 1
SilkTester007
Member


Reged: 12/03/07
Posts: 158
Line Count in Note pad
      #534339 - 11/25/08 07:48 AM


Hi All,

Can any one please let me know how to get the count of number of lines of text in the note pad and how to get the text form a particular line number.


Thanks,
Arun


Post Extras: Print Post   Remind Me!   Notify Moderator  
dimaj
Active Member


Reged: 05/05/05
Posts: 828
Loc: Fremont, CA
Re: Line Count in Note pad [Re: SilkTester007]
      #534367 - 11/25/08 08:46 AM Attachment (133 downloads)

I would say that the easiest way would be bypassing notepad and just reading the file in using ListRead () function. Then once you have your list, you can do a ListCount to get the count and list to get ith element from your list.

If you absolutely must use notepad, download my attachment. It has the framework for Notepad as well as functions to do what you ask for. It also has a sample testcase to demonstrate usage of functions.

Hope this helps

dimaj


Post Extras: Print Post   Remind Me!   Notify Moderator  
Flightdeck73
Junior Member


Reged: 07/07/06
Posts: 61
Loc: Ma
Re: Line Count in Note pad [Re: dimaj]
      #534389 - 11/25/08 09:52 AM

I would just read the file into an Array...

Code:

STRING thisLine
LIST OF STRING FileContents = {...}
HFILE thisFile = Sys_FileOpen ( "C:\Path\FileName" , FM_READ )
while ( Sys_FileReadLine ( thisFile , thisLine ) )
ListAppend ( FileContents , Trim ( thisLine ) )
Sys_FileClose( thisFile )
PRINT ( FileContents[LINE#] )




I am assuming its a .TXT file, there are more efficient ways to read .INI or .xml

--------------------
SILK noob

Edited by Flihtdek73 (11/25/08 09:53 AM)


Post Extras: Print Post   Remind Me!   Notify Moderator  
April_20
Junior Member


Reged: 02/24/06
Posts: 195
Loc: Princeton, NJ
Re: Line Count in Note pad [Re: Flightdeck73]
      #534452 - 11/25/08 02:22 PM

Quote:

I would just read the file into an Array...

Code:

STRING thisLine
LIST OF STRING FileContents = {...}
HFILE thisFile = Sys_FileOpen ( "C:\Path\FileName" , FM_READ )
while ( Sys_FileReadLine ( thisFile , thisLine ) )
ListAppend ( FileContents , Trim ( thisLine ) )
Sys_FileClose( thisFile )
PRINT ( FileContents[LINE#] )




I am assuming its a .TXT file, there are more efficient ways to read .INI or .xml




FileContents is LIST not ARRAY. And it does the same as dimaj code.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Flightdeck73
Junior Member


Reged: 07/07/06
Posts: 61
Loc: Ma
Re: Line Count in Note pad [Re: April_20]
      #534614 - 11/26/08 04:35 AM

Isnt a LIST of Something really an Array?

I have never used the 'ListRead () function. before' but it appears that i could not perform any actions on the data before it is inserted it into the LIST.

Let me know if im incorrect please.

--------------------
SILK noob


Post Extras: Print Post   Remind Me!   Notify Moderator  
SilkTester007
Member


Reged: 12/03/07
Posts: 158
Re: Line Count in Note pad [Re: April_20]
      #534631 - 11/26/08 05:10 AM

Hi ,

By using code

STRING thisLine
LIST OF STRING FileContents = {...}
HFILE thisFile = Sys_FileOpen ( "C:\Path\FileName" , FM_READ )
while ( Sys_FileReadLine ( thisFile , thisLine ) )
ListAppend ( FileContents , Trim ( thisLine ) )
Sys_FileClose( thisFile )
PRINT ( FileContents[1] )

Last line of the note pad is printed,Can any one let me know how to print the text from 1st line to last line continuously.

Thanks,
Arun


Post Extras: Print Post   Remind Me!   Notify Moderator  
Flightdeck73
Junior Member


Reged: 07/07/06
Posts: 61
Loc: Ma
Re: Line Count in Note pad [Re: SilkTester007]
      #534634 - 11/26/08 05:15 AM


Try an indent.
Code:

[-] while ( Sys_FileReadLine ( thisFile , thisLine ) )
[ ] ListAppend ( FileContents , Trim ( thisLine ) )




--------------------
SILK noob


Post Extras: Print Post   Remind Me!   Notify Moderator  
April_20
Junior Member


Reged: 02/24/06
Posts: 195
Loc: Princeton, NJ
Re: Line Count in Note pad [Re: Flightdeck73]
      #534682 - 11/26/08 07:52 AM

Quote:

Isnt a LIST of Something really an Array?

I have never used the 'ListRead () function. before' but it appears that i could not perform any actions on the data before it is inserted it into the LIST.

Let me know if im incorrect please.




LIST is more flexible data structure than ARRAY b/c it doesn't have fixed size.
ListRead function doesn't read the list, but rather creates it by reading the content of the text file into LIST of STRING where each STRING represents separate line from the file.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Flightdeck73
Junior Member


Reged: 07/07/06
Posts: 61
Loc: Ma
Re: Line Count in Note pad [Re: April_20]
      #534705 - 11/26/08 08:37 AM

Quote:


LIST is more flexible data structure than ARRAY b/c it doesn't have fixed size.






Ya your absolutly right.


I guess my question is 'How could i perform an action on the data from the file before its inserted into the list with listRead( )?' I usually like to Trim( ) or evaluate what ive read from the file before it gets place it into a LIST.

--------------------
SILK noob


Post Extras: Print Post   Remind Me!   Notify Moderator  
dimaj
Active Member


Reged: 05/05/05
Posts: 828
Loc: Fremont, CA
Re: Line Count in Note pad [Re: Flightdeck73]
      #534740 - 11/26/08 10:38 AM

Flihtdek73,

You are correct... When you use a ListRead, you cannot perform any actions on a line before it is placed to the List.

dimaj


Post Extras: Print Post   Remind Me!   Notify Moderator  
Mirek_B
Member


Reged: 11/01/06
Posts: 319
Re: Line Count in Note pad [Re: Flightdeck73]
      #534853 - 11/27/08 01:49 AM

Quote:

How could i perform an action on the data from the file before its inserted into the list with listRead( )?



And why would you want to do that?
To manipulate any kind of data first thing you have to do is to acquire that data. Thats what listRead is for, right?
No one says you can not iterate through this list to do whatever you like and put it into another list.
And the reason why first read the data and then manipulate them is far better then to manipulate the data while reading it? Well, its about code transparency. When you are doing two things, it should be in two separate places in the code.


Post Extras: Print Post   Remind Me!   Notify Moderator  
peat
Member


Reged: 10/18/02
Posts: 370
Loc: England
Re: Line Count in Note pad [Re: Mirek_B]
      #534886 - 11/27/08 04:18 AM

There is one situation where you might want to preprocess the data:

If your incoming line length exceeds 512 chars, then ListRead won't handle it. Line lengths > 512 might well be encountered in compressed (ie, all white space removed) HTML files, so this limitation is worth bearing in mind.

I've never tried reading any file that has line lengths this long, so I assume it will probably just truncate the line, rather than throwing an exception.

Regards
Peat


Post Extras: Print Post   Remind Me!   Notify Moderator  
Mirek_B
Member


Reged: 11/01/06
Posts: 319
Re: Line Count in Note pad [Re: peat]
      #534897 - 11/27/08 04:51 AM

Quote:

If your incoming line length exceeds 512 chars, then ListRead won't handle it.



Uh, good to know.
Thanks for pointing it out.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Flightdeck73
Junior Member


Reged: 07/07/06
Posts: 61
Loc: Ma
Re: Line Count in Note pad [Re: Mirek_B]
      #535339 - 12/01/08 04:06 AM

Quote:


.......When you are doing two things, it should be in two separate places in the code.





Thats a pretty good point Mirek. Perhaps i shouldn't do anything while reading the data in initially.

--------------------
SILK noob


Post Extras: Print Post   Remind Me!   Notify Moderator  
MikeBuckley
stranger


Reged: 08/15/06
Posts: 3
Loc: Massachusetts
Re: Line Count in Note pad [Re: Flightdeck73]
      #540352 - 12/23/08 09:21 AM

How about this:

Open the file in Notepad:
Then from the edit menu, select all, and copy
Within the script ListCount(Clipboard.GetText()
(If that doesn't work, then create a LIST OF STRING lsClip = Clipboard.GetText())
Print(ListCount(lsClip))
Should print out the number of lines in the text file.
Go back to Notepad, and dismiss it to clean up the file.


Post Extras: Print Post   Remind Me!   Notify Moderator  
Pages: 1



Extra information
0 registered and 6 anonymous users are browsing this forum.

Moderator:  AJ, jamesso, DJGray, David Reed 

Print Topic

Forum Permissions
      You cannot start new topics
      You cannot reply to topics
      HTML is disabled
      UBBCode is enabled

Rating:
Topic views: 2802

Rate this topic

Jump to

Contact Us | Privacy statement SQAForums

Powered by UBB.threads™ 6.5.5