Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Extra! Macro Scripting - Writing to Log Issue

Posted on 2004-11-12
2
Medium Priority
?
206 Views
Last Modified: 2012-05-05
I have a macro script that inputs data into SAP via Extra screens.

I want to be able to write out errors to a log file.  I have it set up as follows:

Dim chan570Errors As Long                                  'output channel
'Open the channel
File_OpenWrite chan570Errors, strFileLoc & "\Logs\" & Format(Now(), "ddmmyyyy-hhmmss") & "ErrorLog.csv"
'Print out Headers
Print #chan570Errors, "Date", "Error", "POW Record Number", "Item No.", "File Name", "File Location", "Full Location"
'Function Call
    Write_Errors ("Missing Vendor")


'Functions
Sub Write_Errors(strErrText As String)
  'Print out error to channel
  Print #chan570Errors, Now, strErrText, strPOWRecNo, strItemNo, strFileName, strFileLoc,  
  strFullImportFileName
   
  MyScreen.WaitHostQuiet 1000  
End Sub

Sub File_OpenWrite(myChannel As Long, pathName As String)
    myChannel = FreeFile                                   'Return the next unused file number
    Open pathName For Output As #myChannel                 'Open the channel
End Sub
-----------------------------------------------------------------------------------------
The problem that I am having is that I have the Write_Errors function call in several different areas of the script.  However, it will only write to the log file the Header and the first error that it encounters.  It doesn't write out an subsequent errors (there are more since I am testing for all possibilities).

Any ideas as to why this is happening?

Thanks in advance.

Capn

   
0
Comment
Question by:CapnCrnch
2 Comments
 
LVL 6

Accepted Solution

by:
SCDMETA earned 1000 total points
ID: 12572400
Are you getting any runtime errors?  If so, they would be helpful.

Could you turn on error handling in the Write_Errors function?  The Print statement might be throwing an error that is getting ignored by the macro interpreter.

Sub Write_Errors(strErrText As String)
  On Error Goto Errortrap
  'Print out error to channel
  Print #chan570Errors, Now, strErrText, strPOWRecNo, strItemNo, strFileName, strFileLoc,  strFullImportFileName    
  MyScreen.WaitHostQuiet 1000  
  Exit Sub
Errortrap:
    msgbox "Error:" & err.description
End Sub

Is "Dim chan570Errors As Long" falling out of scope, between calls to your macros?  

Try opening the file, writing to the file and closing it all within Write_Errors function.  Not very efficient but it could get you past the problem.
0
 

Author Comment

by:CapnCrnch
ID: 12587061
SCDMETA wrote:
Try opening the file, writing to the file and closing it all within Write_Errors function.  Not very efficient but it could get you past the problem.

---------------------
This is what I ended up doing.  Not very efficient, but it works nonetheless.

Thanks.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question