Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using aspect to read a text file

Status
Not open for further replies.

mikecons

Technical User
Jan 9, 2002
1
US
Hello all! If anyone out here can help me, I would be incredibly appreciative. I am trying to use ProComm to read a list of numbers from a text file, and use them is a script for a Meridian system. The text file would have the numbers separated by carriage returns. For example:

1234567
1111111
3434343

The program is supposed to loop, and continue to enter the numbers until the end of the file is reached. The following program was posted here a few months ago, it is almost exactly what I need. However, when I tried to run it, it only output a carriage return, leading me to believe that it did not read the file correctly (the file is in the right location and named properly).

Can anyone point me in a direction to get this working?? Thanks in advance!

-Mike

proc main
string Fname = "c:\friends.txt"
string authcode[100]
string Line

integer Counter=0
fopen 0 Fname READ TEXT
while not feof 0
fgets 0 Line
Authcode[Counter]=Line
Counter++
transmit "^M"
waitfor "REQ "
transmit "NEW^M"
waitfor "TYPE "
transmit "AUT^M"
waitfor "CUST "
transmit "0^M"
waitfor "SPWD "
transmit "0000^M"
waitfor "CODE "


transmit Line RAW

waitfor "SARC "
transmit "^M"
waitfor "CLASS "
transmit "1^M"

endwhile


endproc
 
Here's a script that should do the trick for you:

proc main
string sLine

fopen 0 "c:\autoexec.bat" READ TEXT
while not feof 0
fgets 0 sLine

<do whatever with the data...>

endwhile
fclose 0
endproc

One thing to check if you are having problems is using the usermsg or statmsg command to output the text that you retrieved from the file. Depending on the format of your data, there may be a carriage return and/or linefeed at the end of the line. These extraneous characters will shows up as a black square. If this is the case with your data, you can use the strdelete command to clean up your string before doing further processing on it.
 
I tried your code with the Meridian commands commented out, and it is reading the text file as LINE correctly.

I would suggest you leave the usermsg in for testing where I inserted it, take all the &quot;;&quot; comments out of the script, and see if the Meridian is recieving it correctly.

Code:
proc main
   string Fname = &quot;c:\friends.txt&quot; 
   string authcode[100]                
   string Line                 

   integer Counter=0             
   fopen 0 Fname READ TEXT      
      while not feof 0           
      fgets 0 Line                 
      Authcode[Counter]=Line      
      Counter++                
   ;transmit &quot;^M&quot;            
   ;waitfor &quot;REQ &quot;       
   ;transmit &quot;NEW^M&quot;            
   ;waitfor &quot;TYPE &quot;         
   ;transmit &quot;AUT^M&quot;           
   ;waitfor &quot;CUST &quot;            
   ;transmit &quot;0^M&quot;           
   ;waitfor &quot;SPWD &quot;            
   ;transmit &quot;0000^M&quot;          
   ;waitfor &quot;CODE &quot;          
   
   usermsg Line  
     

   ;transmit Line RAW          
      
   ;waitfor &quot;SARC &quot;
   ;transmit &quot;^M&quot;
   ;waitfor &quot;CLASS &quot;
   ;transmit &quot;1^M&quot;
   
     endwhile             
 
     
   endproc
Robert Harris
Communications Advantage
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top