#39871 - 2003-05-02 07:06 PM
ReadLine Function
|
Stryder
Lurker
Registered: 2003-04-28
Posts: 2
Loc: Kansas
|
I need to be able to have a script read a text file and capture the value of each line in the file. I know how to read a line with readline or you can even manually add another readline ($x = readline + readline) and get the first two lines of the text file. Is there a way to have the script determine how many readline's it needs to perform to get the entire contents of the file?
Below is an example of what I am working with and I have the script manually reading the first two lines of the file.
If Exist ("\\pathtofile\$month$day.txt") $msgtext = $msgtext + 'Birthdays for today are:' + chr(10) IF Open(3, "\\pathtofile\$month$day.txt") = 0 $x = ReadLine(3) + chr(10) + ReadLIne(3) Close (3) EndIf $msgtext = $msgtext + chr(10) + $x + chr(10) + chr(10) EndIf
I then use a messagebox to display the value of $msgtext.
Can someone help?
Thanks
|
|
Top
|
|
|
|
#39872 - 2003-05-02 07:10 PM
Re: ReadLine Function
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
could you not do: $x=readline(1) while not @error ? $x $x=readline(1) loop ? "end of file"
|
|
Top
|
|
|
|
#39876 - 2003-05-03 08:18 AM
Re: ReadLine Function
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
Hello Brian,
Here is an example of doing what you're looking to do. You need to supply the real path to the BIRTHDAYS.INI file and you need to fill it out to include ALL MONTHS and ALL DAYS as well as ALL USERS with their Birthday on that month and day.
It is possible to do this other ways, but this should suffice or at least give you a little more insight on how it can be done.
Hope this helps, if you have questions please don't hesitate to ask. The Piranha members around here will be happy to help.
DisplayBirthdays.kix
$Y = SUBSTR(@DATE, LEN(@DATE) - 9, 4) $M = SUBSTR(@DATE, LEN(@DATE) - 4, 2) $D = SUBSTR(@DATE, LEN(@DATE) - 1, 2) $MyFile=("C:\TEMP\birthdays.ini") $Birthdays=ReadProfileString ($MyFile, $M, $D) $AlertBD=MessageBox("Today is "+@DATE+@CRLF+"Happy Birthday to "+$Birthdays, "Happy Birthday", 64)
birthdays.ini
[01] 01=John Doe 02=Bill Smith 03=Brian Wilson 04=George Garthy 05=Jane Doe [02] 01=John Miller, Jack Black 02=Karen Gleason [03] 01=Wendy Feiten 02=Brad Jones [04] 01=Greg Engle 02=Tim Vinter 03=Beth Angel [05] 01=Carl Celt 02=Kevin Empire, Andy Burke 03=Helen Birch 04=Celine Welsh, Bart Sordel
|
|
Top
|
|
|
|
#39879 - 2003-05-03 07:55 PM
Re: ReadLine Function
|
Sealeopard
KiX Master
   
Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
|
code:
$bd=readprofilestring(@SCRIPTDIR+'\birthdays.ini',@MONTH,@MDAYNO) if $bd $rc=messagebox('Todays Birthdays are:@crlf' + $bd, 'Happy Birthday', 64) endif
for the following BIRTHDAY.INIcode:
[January] 1=John Doe 5=Jane Doe [February] 6=John Miller, Jack Black
Granted, the .INI file is longer, but more readable and the KiXtart code itself is shorter
_________________________
There are two types of vessels, submarines and targets.
|
|
Top
|
|
|
|
#39880 - 2003-05-03 09:42 PM
Re: ReadLine Function
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
See Brian,
What did I tell you about those Piranha.
All these good ideas. Let me recommend though, that regardless of who's idea/code you use. Make sure you liberally comment the code so that in the future you'll know what and how it does it.
Code that is left alone for long periods of time can be difficult to decipher unless you work with it daily. I know some Admins write stuff and don't look at it or touch it for Months at a time, then when they go back they have trouble knowing what it does because they don't script or code daily. Unlike some of the Piranha here who play with it daily and can get away with this KiX Golf coding style (though if done in production, the next Admin to come along won't be happy with them ) Commenting code is a Best Practice but few do it.
|
|
Top
|
|
|
|
#39882 - 2003-05-04 04:23 AM
Re: ReadLine Function
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11629
Loc: CA
|
I hope not. I for one do not share that attitude. You've handed nothing on a Silver Platter at work, but rather you've done your job, which in my opinion should include allowing others to easily assist you or take over the job in case you are injured, promoted, or laid off.
Why would you want someone else to suffer? Just don't see the reason why one human being would want another to suffer when they had done nothing to you.
|
|
Top
|
|
|
|
#39886 - 2003-05-04 08:27 PM
Re: ReadLine Function
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Can see both sides of the coin here.. Documentation is good in the event you are no longer able to perform script functions.. However, there is a good point, that if you "squeeze" the script down, the time it takes to parse it through will be less. This, then begs the question at what expense? Something so cryptic that nobody understands? Or, is just something infinitessimal?
So, for example, you take the script from 40ms to 20ms, is that a good trade-off? These numbers are still less than a second.
Thanks,
Kent
|
|
Top
|
|
|
|
#39890 - 2003-05-05 11:43 PM
Re: ReadLine Function
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Wouldn't this be a good opportunity to use something like KIXREF and spool this info to a separate file? The only downfall to that would be is that if you had any updates, you would have to re-run it.
Kent
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 765 anonymous users online.
|
|
|