locked
TextWindow page by page RRS feed

  • Question

  • Hello,

    an easy way to have a much longer textwindow (more then 300 readable lines) ... probably already published but i couldn't found the solution

    As I have long programs ... if debug=true the text is send to the textwindow AND the file "debug.txt" but you can change in the debugfunction the remainder to another length to read the textwindow page by page - the program will wait and the textwindow pause still you hit the space (the cursor needs to be inside the textwindow)

    If debug is something else debug=false  the text is send only to the debugfile.   program published as QDK083  you can also from inside the program start a new page resetting the counter to 0, etc 

    I still have a question ... when sending to the debug file the color-escape sequences in HP-PCL to print the line in color. I don't find a program printing the lines in color to the pc-screen.

    Debug="True" 'to set to false 
    counter=0
    args = ""
    DebugFile="debugFile.txt"
    File.DeleteFile(DebugFile)
    File.AppendContents(DebugFile,"DebugFile : "+Clock.date+" = "+Clock.time)
    File.AppendContents(DebugFile,"=================================")
    for x=1 to 500
      LDCall.Function("DebugFunc","x= "+x+" !")
    endfor
    
    'END PROGRAM
    
    'Function subroutine 
    Sub DebugFunc
      if debug then
        TextWindow.WriteLine(args[1])
        counter=counter+1
        if math.remainder(x,100)=0 then 
          TextWindow.Pause()    'or textwindow.PauseWithoutMessage()
        endif 
      endif
      File.AppendContents(DebugFile,args[1])
    EndSub






    • Edited by Eddy Abts Sunday, April 12, 2020 9:23 AM
    Sunday, April 12, 2020 8:27 AM

Answers

  • When trying to use the above listing it looks like the program runs, but then I wondered where did the "debugFile.txt go? I ended up changing the "File.AppendContents(Debugfile,args[1]" to "Status=File.AppendContents(Debugfile,args[1]". Then do a TextWindow.Writeline(Status) and you'll find the file wasn"t  created. To creates the file it needs the full path like "c:\temp\debugfile.txt". Then it will work. I got into this by wondering where the file was actually at. It's a good practice to check the status of file write commands to be sure that they were actually written.

    JR

    Tuesday, April 21, 2020 1:06 AM
    Answerer
  • Eddy,

    Here's another interesting aspect of your program.

    How can you know if the "LDCall.Function" actually worked? In the actual function if you make a variable and call it "return" the "LDCall.Function" will return the value that is in "return" to where the function was called. So, if I make the variable "return" pickup the status of the "File.appendcontents" then that will get returned to the LDCall.Function. Then for the function call make it's variable the word "Status" I can then do a textwindow.writeline to show that the function status ("failed" or "success"). 

    Also, I was wondering how you actually use this section of code in your actual programs? You said that you have really long programs and i would guess they report errors which go to the debug routine. I am interested in how you make that work?

    Thanks,

     


    JR

    Tuesday, April 21, 2020 11:16 AM
    Answerer

All replies

  • When trying to use the above listing it looks like the program runs, but then I wondered where did the "debugFile.txt go? I ended up changing the "File.AppendContents(Debugfile,args[1]" to "Status=File.AppendContents(Debugfile,args[1]". Then do a TextWindow.Writeline(Status) and you'll find the file wasn"t  created. To creates the file it needs the full path like "c:\temp\debugfile.txt". Then it will work. I got into this by wondering where the file was actually at. It's a good practice to check the status of file write commands to be sure that they were actually written.

    JR

    Tuesday, April 21, 2020 1:06 AM
    Answerer
  • Hello JR,

    Thanks for your remark it's true ! I was removing in line 4 the fullpath just before pubishing as the test was located far in a subdirectory. Before publishing the program as I did some testing the file debug.txt was already created. In fact finding back the file is often a tricky problem ... and testing the status especially when you are writing to "a write-protected" device could avoid other problems. 

    The file I wanted to put in place in line 4 was something as    DebugFile="D:\DebugFile.txt"  

    Often you can use also :    DebugFile=Program.Directory+"\debugFile.txt"  

    Or make it more visible and to verify the full path with some code such as 

    DebugFile=Program.Directory+"\debugFile.txt"  
    TextWindow.foregroundcolor="Red"
    Textwindow.writeline("DebugFile = "+DebugFile) 
    TextWindow.foregroundcolor="White"
    File.DeleteFile(DebugFile) ‘to initialize the debugfile as the file will be created automatically. 



    • Edited by Eddy Abts Tuesday, April 21, 2020 7:59 AM
    Tuesday, April 21, 2020 7:56 AM
  • Eddy,

    Here's another interesting aspect of your program.

    How can you know if the "LDCall.Function" actually worked? In the actual function if you make a variable and call it "return" the "LDCall.Function" will return the value that is in "return" to where the function was called. So, if I make the variable "return" pickup the status of the "File.appendcontents" then that will get returned to the LDCall.Function. Then for the function call make it's variable the word "Status" I can then do a textwindow.writeline to show that the function status ("failed" or "success"). 

    Also, I was wondering how you actually use this section of code in your actual programs? You said that you have really long programs and i would guess they report errors which go to the debug routine. I am interested in how you make that work?

    Thanks,

     


    JR

    Tuesday, April 21, 2020 11:16 AM
    Answerer
  • Hello JR,

    I will open another topic as "debugging" ... following the program-flow (The small program is ZCP924)

    Tuesday, April 21, 2020 4:19 PM
  • Eddy,

    I loaded program ZCP924 and am reviewing it. Starting another thread for debugging would be great! 

    Thanks,


    JR

    Tuesday, April 21, 2020 5:16 PM
    Answerer