Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'StreamPosition in function' topicStudent Support Forum > General > "StreamPosition in function"

Next Comment >Help | Reply To Topic
Author Comment/Response
10/17/00 06:44am

Below is an example of StreamPosition not working when called in a function.

First comes the file myfile.txt containing the company name ''my name''; we want to retrieve a number which happens to be 23.75.

(begin of myfile.txt)

<td bgcolor=''#ecf4fd'' align=''left''><font size=''1'' face=''Arial'' color=''#000094''><NOBR>my name</NOBR></font></td>
         <td bgcolor=''#ffffff'' align=''center''><font face=Arial size=''1''>23.75</font></td>
         <td bgcolor=''#FF6363'' align=''center''><font face=Arial size=''1''><img
(end of myfile.txt)

I would expect the following code to take us to the right place. The Find command succeeds in taking us to the company name, but StreamPosition returns 0.

findRate[companyName_, fileName_] :=
Module[{pos,sMyfile}, sMyfile := OpenRead[fileName];
SetStreamPosition[sMyfile, 0];
Find[sMyfile, companyName];
Skip[sMyfile, Word, 4];

The last seven commands by themselves work all right. But

findRate[''my name'', ''c:\\myfile.txt'']

just trivially returns 10. Did I make any newcomer's mistake?

URL: ,

Subject (listing for 'StreamPosition in function')
Author Date Posted
StreamPosition in function Carol 10/17/00 06:44am
Re: StreamPosition in function Forum Modera... 10/20/00 12:21pm
Next Comment >Help | Reply To Topic