Jump to content
AC Tool Forums
Sign in to follow this  
Amuk

reading a text file into a constant.

Recommended Posts

I am trying to figure out how to read a text file into a constant. I know I can do FileRead and get one line, but that is not enough.

My end goal is to email the contents of the file out using actool. Since there is no atachment command I saw, i was trying to read the file line by line into the mailbody, but I guess that is just a one line field. Each line overwrites it before it is sent.

 

Is there a different way I should try to do this?

Thanks

 

 

What I had tried...

 

Procedure log

SetConst $Subject = Review log.

Call ReadLog

Fileclose File3

Call MailMe

End

 

Procedure ReadLog

FileOpen File3, $Log

FileReset File3

While 1=1

FileRead File3, Body

MailBody $Body

If {EOF} = True

Exit

End

End

End

 

Procedure MailMe

MailBody $Body

MAILFROM $From

MailTo $SendMailTo

MailSubject $Subject

MailHost $MyHost

MailSend

End

Share this post


Link to post
Share on other sites

Still not a better way to do this?

 

I worked around this by making an email for every line, but is seems a little sloppy and I would much rather be able to have the contents of the log sent in 1 email rather then 10 or more.

 

so my workaround is:

 

 

Procedure log

SetConst $Subject = Review log.

Call ReadLog

Fileclose File3

Call MailMe

End

 

Procedure ReadLog

FileOpen File3, $Log

FileReset File3

While 1=1

FileRead File3, Body

MailBody $Body

Call MailMe

If {EOF} = True

Exit

End

End

End

 

Procedure MailMe

MailBody $Body

MAILFROM $From

MailTo $SendMailTo

MailSubject $Subject

MailHost $MyHost

MailSend

End

Share this post


Link to post
Share on other sites

Took me some digging through old macro's to find the answer. :blink:

 

(*
Filename: Mail_File.mac
By Bear 10/3/2010
*)
constants
 FileValue =
 ListFile = D:\4_line_test.txt
 body =
 Num = 1
 // Set Debug to 1 to see Debug code in Test Log tab.
 Debug = 0
End

Constructs
 File1=File
 TestLine=List
End

FileOpen File1, $ListFile
FileReset File1
While 1 = 1
 FileRead File1, $FileValue
 If EOF File1
   Break
 Else
   ListAdd TestLine, $FileValue
 End
End
FileClose File1

ListCount TestLine, $FileValue

If $Debug = 1
 TimeStamp $FileValue
End

Loop $FileValue
 Set Body = $Body + TestLine[$Num]
 If $Debug = 1
   Timestamp Line ( TestLine[$Num] )
   Timestamp ----------
   TimeStamp Body ( $Body )
 End
 Inc Num
End

MailBody $Body
TimeStamp Body ( $Body )
(*
FileName: 4_line_test.txt

This is Line 1 of a Test File.
This is Line 2 of a Test File.
This is the 3rd Line of a Test File.
This is the Final Line of a Test File.
*)

 

Changed it so the TimeStamp's only display in the Test Log Tab when the Constant Debug = 1. Except the Final $Body one.

Edited by Bear

Share this post


Link to post
Share on other sites
Took me some digging through old macro's to find the answer. :blink:

 

Changed it so the TimeStamp's only display in the Test Log Tab when the Constant Debug = 1. Except the Final $Body one.

 

Cleaned it up some more, In this version it's a Plugin (.INC). The Zip contains the (.INC) plus an Example (.MAC) that calls the (.INC).

Also removed all the Debug Code. ;)

Mail_File.zip

Edited by Bear

Share this post


Link to post
Share on other sites

Thanks Bear. That does read it all into the one constant.

I was trying to make is display a little better, and tried adding,

ListAdd TestLine, $FileValue

ListAdd TestLine, {RETURN}

to try and make each line read a line in the list. It did not work, and just inserted {RETURN} between every read line.

 

Im still trying to figure that part out, but if there is a suggestion...

Share this post


Link to post
Share on other sites


constructs
  
  file1=file
  list1=list
  
end

constants
  
  unfortune_timer_txt=C:\Users\DZIUS\Desktop\AC_tool_data\unfortune_timer_txt.txt
  file_read=0
  read_line=1
  unfortune_timer=1
  
end

fileopen file1, $unfortune_timer_txt
filereset file1

while 1 = 1
  
  fileread file1, $file_read
  
  if {LoopNo} = $read_line
    
    compute $unfortune_timer = $file_read
    
    fileclose file1
    
    Break
  end
  
end


while 1=1
  
  delay 360
  
end


stop

 

I was looking for something very similar and as I break through, here is a sample macro to read a specific line from text file. It can be used to save and read values and create a text file I guess.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and to our Privacy Policy.