Jump to content

Get script line number before compiling


 Share

Go to solution Solved by mrider,

Recommended Posts

I often use this in my script

If @error then
MsgBox(262144 + 8192 + 16, "Error: 455", "Process failed, cannot find object or connection timeout.")
EndIf

where 455 is line number in my au3 file, the problem is when I add new lines before line 455, the script line number change, and no longer valid, I know I can use @ScriptLineNumber, but as help file says:

Line number currently being executed. Useful for debug statements such as the calling line number for a function. (Not significant in compiled scripts)

 

this is not significant in compiled scripts, what I want is some scite function maybe, than can set line number before compiling, so the line number is stitll same when displayed on uncompiled and compiled script,

Link to comment
Share on other sites

  • Developers

The easiest way is to use @ScriptLineNumber and run au3stripper to generate a single script which is exactly stored in the generated EXE.

See Full SciTE4AutoIt3 installer for details on au3stripper.

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi Jos, thanks for your suggestion,

I know that Jos, but I find it hard to do, that make my script even bigger and difficult to maintain, I have a few thousands of line on my main au3 file, not including included file.

Edited by ngskicker
Link to comment
Share on other sites

  • Developers

Hi Jos, thanks for your suggestion,

I know that Jos, but I find it hard to do, that make my script even bigger and difficult to maintain, I have a few thousands of line on my main au3 file, not including included file.

Why?

You keep on maintaining your original script as you do today.

Just use the Script_Stripped.au3 version for the reference to the error lines.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi Jos, thanks for your suggestion,

 

I know that Jos, but I find it hard to do, that make my script even bigger and difficult to maintain, I have a few thousands of line on my main au3 file, not including included file.

 

You can use @ScriptLineNumber without Au3Stripper.

Just use this in your MsgBox(....

If @error then
MsgBox(262144 + 8192 + 16, "Error: " & @ScriptLineNumber, "Process failed, cannot find object or connection timeout.")
EndIf

btw.

using Au3Stripper you can use this parameter:

 

- Added #Au3Stripper_Parameters Parameter:

        - /rsln -> Replace @ScriptLineNumber with the actual line number for source debug purposes with compiled scripts. (Idea of mLipok)

 

 

EDIT:

and remember

When you use @ScriptLineNumber in Run mode (not compiled) this macro  ( I mean @ScriptLineNumber) return line number relative to each au3 file separately.

 

EDIT2:

but if you want to use compiled version then the only way is using @ScriptLineNumber with Au3Stripper and /rsln parameter

Then you get Line Number which all are relative to a single file [your_Script_name]_Stripped.au3

But this is very easy to find exactly that one line, and after that you can easily find the same line in you original script file.

I use it almost every day.

Summarizing: just like Jos say here:

 

You keep on maintaining your original script as you do today.

Just use the Script_Stripped.au3 version for the reference to the error lines.

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

  • Solution

I realize this isn't going to be very helpful in this context, since my solution uses Perl rather than AutoIt.  Having said that, I have a program that all totalled is roughly 10k LOC, and it would be interesting (in the Chinese curse sense) to maintain the internal logging line numbers.  And considering that there are 12 different modules, I didn't want to go the route of one huge source file with line numbers for that - I log the module where the problem occurs along with the line number in that module.

My solution is a separate Perl program that parses the code, tracks the current file line number, and then rewrites the source file with proper numbers.  I run this program after any change to the source. 

Again, I realize this won't help you directly.  But maybe it can give you an idea?

My Perl code is:

#!/usr/bin/perl
use strict;
use warnings;

my @files = qw(
    Advanced.au3
    Containing.au3
    FileAttributes.au3
    FileDates.au3
    FileSearch.au3
    FileSearch_Globals.au3
    FileSize.au3
    Logging.au3
    NameAndLocation.au3
    Preferences.au3
    SQLite3.au3
    ContextMenu.au3
);

foreach my $file (@files) {
    renumber_file($file);
}

sub renumber_file {
    my $fn = shift;
    my @lines;
    my $line;
    my $changed = 0;
    my $linenum = 1;
    open(my $in, "<", $fn) or die;
    while(<$in>) {
        if (m/(^\s*WriteLog\s*\(".*?", ".*?", )[0-9]+(.*\))$/) {
            $line = $1 . $linenum . $2 . "\n";
            $changed++;
        } else {
            $line = $_;
        }
        push @lines, $line;
        $linenum++;
    }
    close($in);

    if($changed) {
        $line = 0;
        open(my $out, ">", $fn) or die;
        foreach $line (@lines) {
            print $out $line;
        }
        close($out);
    }
}

How's my riding? Dial 1-800-Wait-There

Trying to use a computer with McAfee installed is like trying to read a book at a rock concert.

Link to comment
Share on other sites

Hi @jos, thanks to you and @mLipok now I understand what you mean, I try it and it's not bad,

and @mrider, you give me good idea, combining with AutoItWrapper Run Before/After this is also good solutions, thanks all of you

this is my script:

#include <File.au3>

If(Number($CmdLine[0]) >= 1) Then
    _RenewLineNumber($CmdLine[1])
EndIf

Func _RenewLineNumber($sFileList)
    Local $sFileLines
    _FileReadToArray($sFileList, $sFileLines)

    For $i = 1 To $sFileLines[0]
        If StringInStr($sFileLines[$i], "Error: ") Then
            $sFileLines[$i] = StringRegExpReplace($sFileLines[$i], '(["])(\bError: [\d]{1,})(["])', '"Error: ' & $i & '"')
        EndIf
    Next

    _FileWriteFromArray($sFileList, $sFileLines, 1)
EndFunc

then I add

#AutoIt3Wrapper_Run_Before=%scriptdir%\__AddLineNumber.exe %in%

on my other script, so every time I compile my script, my error line ("Error: 455") is updated, please tell me if something I miss.

Edited by ngskicker
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...