Jump to content

Prevent from running wrong file


Lope
 Share

Recommended Posts

While I'm working on a script thats comprised of multiple files I use multiple instances of SciTE and have about 5 files open at any point in time.

Often I accidentally press F5 in the wrong file, and usually get error messages saying $blah is not declared yet, and then I don't realize immediately I've run the wrong file and go looking for the problem :idea:

So I've done this

;first line of the main file
Global $running_the_wrong_file=False

;first line of include file
If $running_the_wrong_file Then Beep();if you run any file other than PyramidClientInstall.au3 from Debug mode it will say WARNING: $youre_running_the_wrong_file: possibly used before declaration. This is to prevent confusing errors when you're busy editing multiple au3 files.

(I realize it won't ever beep)

Any better way to do this?

Link to comment
Share on other sites

I dunno: that seems like a pretty straightforward, even clever, way of doing it.

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Include files have a common feature. They contain #include-once at the top of the file. Read the first line of the file and warn if #include-once is found.

Example:

#include-once

If Not @Compiled And FileReadLine(@ScriptFullPath, 1) = '#include-once' Then
    SplashTextOn(@ScriptName, 'This is an include file', 300, 60)
    Sleep(2000)
    Exit 1
EndIf

:idea:

Link to comment
Share on other sites

Mhz: Admittedly I have not tested your code, but I don't think it would work. From the tests I've done, if you run the wrong file it won't even execute code before it checks if all the variables are declared.

Link to comment
Share on other sites

Include files have a common feature. They contain #include-once at the top of the file. Read the first line of the file and warn if #include-once is found.

This is, of course, assuming that they were created in a thoughtful manner.

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Mhz: Admittedly I have not tested your code, but I don't think it would work. From the tests I've done, if you run the wrong file it won't even execute code before it checks if all the variables are declared.

@Lope

I tested before posting. If your includes can not pass syntax check using Au3check then fix them. I know all the includes that I use pass syntax checking using Au3check. :idea:

This is, of course, assuming that they were created in a thoughtful manner.

Now for you, Fulano.

Stating idiotic excuses for others is rather destructive. If people are going to add the example I gave and not put #include-once at the top of the include file, then perhaps they should give up on doing any form of programming. And for you to have this opinion is rather self defeating. I have noticed you stirring trouble previously in topics with your opinions and I consider you should just STFU with your opinions of what YOU think. There are no statistics to prove your opinions so they are all of your own creation. So do us a favor and keep your worthless opinions to yourself.

Link to comment
Share on other sites

Mhz

@Lope

I tested before posting. If your includes can not pass syntax check using Au3check then fix them. I know all the includes that I use pass syntax checking using Au3check.

You're missing the point bud. The reason its not obvious whether you're running the right file is sometimes you run the main file with a syntax error, and get an error saying "blah not declared" other times you run the wrong file and it says "blah not declared" even if there are no errors in any files.

the method I posted will let you know instantly that you're running the wrong file regardless of whether the code works or not :idea:

Its just a time saver.

Mhz

Now for you, Fulano.

Stating idiotic excuses for others is rather destructive.

Geez bro, I think you took that in a really bad way for no reason. Looks to me like Fulano was just adding a reminder that people should remember to have #include-once on the first line if they use your method.

I can never figure out how to quote people on any forums lol. It should be so simple but I seem to miss it :) I had to manually write in openbracket quote closebracket. *shakes head*

Edited by Lope
Link to comment
Share on other sites

I miss the point?

...sometimes you run the main file with a syntax error, and get an error saying "blah not declared"

You fix the syntax error to correct it. I do not see a misunderstanding there.

...other times you run the wrong file and it says "blah not declared" even if there are no errors in any files.

Now that is a doozy I must admit. You get errors but there are no errors. That logic has a flaw in it.

the method I posted will let you know instantly that you're running the wrong file regardless of whether the code works or not :idea:

Its just a time saver.

On syntax free includes, your idea will bring a syntax error. That is the ideal scenario to you? It is not to me.

...Looks to me like Fulano was just adding a reminder that people should remember to have #include-once on the first line if they use your method.

I fail to see how you interpret it as a reminder. It assumes that people do not use #include-once which is a stupid opinion based on what exactly?
Link to comment
Share on other sites

I fail to see how you interpret it as a reminder. It assumes that people do not use #include-once which is a stupid opinion based on what exactly?

I'm sorry to took offence, I was merely pointing out that consistent use of good programming style should not be assumed when giving out help.

Yes, all include files should have #include-once at the top for reasons which are obvious once the fledgling programmer learns the command exists, and that AutoIt doesn't handle that for them automatically like other languages (Python comes to mind). Unfortunately neither of these are a given when talking with someone new to the language (or programming in general).

If people are going to add the example I gave and not put #include-once at the top of the include file, then perhaps they should give up on doing any form of programming.

This is a really intolerant statement - should I tell my 1 year old to give up on any form of walking because she falls from time to time? Look at the code that some of the beginners post - it's very clear that they haven't ever taken even a beginning programming course. Give them some time, the ones that have good brains will clue in and become better and the others will get frustrated and leave.

Or perhaps I should say, the ones with thick skins will stick around and the ones unwilling to put up with the abuse will move on to something less powerful, but with a less venomous community.

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

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...