Sign in to follow this  
Followers 0
JoeSixpack

AND / OR use

12 posts in this topic

im having trouble using AND OR operators..

here's the code as it's currently written:

If $Cmdline[0] >= 3 AND $Cmdline[2] = "Repeat" OR $Cmdline[2] = "R" AND $Cmdline[3] >= 2 Then $repeat=$Cmdline[3]

but there is a problem.. it's getting broken up and the script see's it as to half pieces..

i tried putting AND OR but that dont work either.

the following 2 changes fix it

here i just added $Cmdline[0] >= 3 to the 2nd part.. which fixes the problem fine but i'd like to know if there is a way i can avoid this in the future.

If $Cmdline[0] >= 3 AND $Cmdline[2] = "Repeat" OR $Cmdline[2] = "R" AND $Cmdline[3] >= 2 Then $repeat=$Cmdline[3]

is a bit longer but works also.

If $Cmdline[0] >= 3 Then
  If $Cmdline[2] = "Repeat" OR $Cmdline[2] = "R" Then
   If $Cmdline[3] >= 2 Then $repeat=$Cmdline[3]
  Endif
Endif

could someone explain to me how i could write this on a single line having it only check $cmdline[0] once? without having to double it up?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

im having trouble using AND OR operators..

here's the code as it's currently written:

If $Cmdline[0] >= 3 AND $Cmdline[2] = "Repeat" OR $Cmdline[2] = "R" AND $Cmdline[3] >= 2 Then $repeat=$Cmdline[3]

but there is a problem.. it's getting broken up and the script see's it as to half pieces..

i tried putting AND OR but that dont work either.

the following 2 changes fix it

here i just added $Cmdline[0] >= 3 to the 2nd part.. which fixes the problem fine but i'd like to know if there is a way i can avoid this in the future.

If $Cmdline[0] >= 3 AND $Cmdline[2] = "Repeat" OR $Cmdline[2] = "R" AND $Cmdline[3] >= 2 Then $repeat=$Cmdline[3]

is a bit longer but works also.

If $Cmdline[0] >= 3 Then
  If $Cmdline[2] = "Repeat" OR $Cmdline[2] = "R" Then
   If $Cmdline[3] >= 2 Then $repeat=$Cmdline[3]
  Endif
Endif

could someone explain to me how i could write this on a single line having it only check $cmdline[0] once? without having to double it up?

If ($Cmdline[0] >= 3 AND $Cmdline[2] = "Repeat") OR ($Cmdline[2] = "R" AND $Cmdline[3] >= 2) Then

Edit: After taking another look at your code I think this is what you want

If $Cmdline[0] >= 3 AND ($Cmdline[2] = "Repeat") OR ($Cmdline[2] = "R") AND $Cmdline[3] >= 2 Then

You could even use nested If's

If $Cmdline[0] >= 3 Then
 If ($Cmdline[2] = "Repeat") OR ($Cmdline[2] = "R") AND $Cmdline[3] >= 2 Then 
EndIf
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

If ($Cmdline[0] >= 3 AND $Cmdline[2] = "Repeat") OR ($Cmdline[2] = "R" AND $Cmdline[3] >= 2) Then

Edit: After taking another look at your code I think this is what you want

If $Cmdline[0] >= 3 AND ($Cmdline[2] = "Repeat") OR ($Cmdline[2] = "R") AND $Cmdline[3] >= 2 Then

You could even use nested If's

If $Cmdline[0] >= 3 Then
 If ($Cmdline[2] = "Repeat") OR ($Cmdline[2] = "R") AND $Cmdline[3] >= 2 Then 
EndIf
1 and 2 have the same problem as my attempts

the 3rd one works it's a little cleaner then mine.. i'd like to get this all on one line if possible though.

what im trying to do is:

is $cmdline[0] is 3 or more.. if yes continue, if no check no more and skip

if $cmdline[2] equals "repeat" or just "r", if yes continue, if no check no more and skip.

if $cmdline[3] is 2 or more. then execute command.., if no check no more and skip.

the reason i need it to check in that order is it will whine about incorrect array size or what ever if $cmdline[2] or [3] does'nt exist and it tries to check.

the reason i want to get this all on one line is i dont like having If statements larger then one line unless i need to do more then one thing, i think it's possible but dont know how. without writing "$Cmdline[0] >= 3" again for the 2nd part after OR.

Edited by JoeSixpack

Share this post


Link to post
Share on other sites

1 and 2 have the same problem as my attempts

the 3rd one works it's a little cleaner then mine.. i'd like to get this all on one line if possible though.

what im trying to do is:

is $cmdline[0] is 3 or more.. if yes continue, if no check no more and skip

if $cmdline[2] equals "repeat" or just "r", if yes continue, if no check no more and skip.

if $cmdline[3] is 2 or more. then execute command.., if no check no more and skip.

the reason i need it to check in that order is it will whine about incorrect array size or what ever if $cmdline[2] or [3] does'nt exist and it tries to check.

the reason i want to get this all on one line is i dont like having If statements larger then one line unless i need to do more then one thing, i think it's possible but dont know how. without writing "$Cmdline[0] >= 3" again for the 2nd part after OR.

I messed up #2

If $Cmdline[0] >= 3 AND ($Cmdline[2] = "Repeat" OR $Cmdline[2] = "R") AND $Cmdline[3] >= 2 Then

I would use the nested If's. That gives you a bit more flexibilty for future code. For Example...

If $Cmdline[0] >= 3 AND $Cmdline[3] >= 2 Then
   If $Cmdline[2] = "Repeat" OR $Cmdline[2] == "R" Then
      Do this
   ElseIf $Cmdline[2] = "Recurse" OR $Cmdline[2] == "r" Then
      Do something else
   Else
      MsgBox(0,"Error", You have used an invalid command switch")
   EndIf
EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

aye, actually that line it self only needs to do that one thing, the variable it's to change already has a value..

but um.. ya i think i can actually save a little bit by combining in with some other cmd checks.. although i'd still like to know if it's possible to get that all onto one line or not without duplicating the first condition into the 2nd if anyone has any ideas.

Share this post


Link to post
Share on other sites

I don't understand the desire to "get it all on one line". Compact code is good, but readable code is better.

Consider using a Switch.

;o)

(or


nothing is foolproof to the sufficiently talented fool..

Share this post


Link to post
Share on other sites

I don't understand the desire to "get it all on one line". Compact code is good, but readable code is better.

Consider using a Switch.

;o)

(or

um.. my code is anything but compact it's offten messy and needlessly ineffecient, i r nubi..

but as far as readability i actually find it easier to read it when it's on one line unless it does more then one thing that was a big reason why i wanted it on one line not to try and make it uber compact.

but uh maybe could you explain the use of a switch im not sure what that is?

i made the changes. if anyone wants to check it out.. comments make up roughly half the file size rofl..

it's a simple script.. that emits tones using the beep command but with a difference..

a lot of the old beep.com and beep.exe programs from dos days dont work right in winnt,2k,xp (probably not vista either)

i found a few that worked on windows but they only let you emit one tone per execution which means if you want anything interesting

you had to use batch files and execute the program dozens of times.

of course you could also echo bell char with a batch file but you can't adjust duration or tone.

anyway primarily wanted a little song or something to play using the pc's speaker on a headless server i've got running..

since i can not see when it's loading up i have to just kinda guess when it's done based on disk activity or try to access it.

this script fits the bill i have it start and play a list of tones when ever it's done booting up.

Share this post


Link to post
Share on other sites

A "Switch" is a language contruct designed to replace old-school if/then type statements. It's fast, extremely readable, and usefully; switches can also be nested. Check the AutoIt manual page.

About your script, you say it defaults to playing a single beep if no command-line paramtertes are given, but I can't see where it does that. Does it require the text file to be present? If so, your script should probably create that text file itself if it doesn't exist (either by physically writing it, or using FileInstall to place it somewhere)

If you are noob, even if you're not, and enjoy messing with the peecee speaker tones, you might want to check out the source for the alarms section in my clock. There's an infinite variety of beeps, sirens, buzzers, even phone rings, all using the peecee speaker, and controlled by a simple set of ini parameters. It's pretty wild, but the code is really very simple..

for $a = 1 to $repeat
    for $i = $bottom to $beeps step $step
        Beep($scaler * $i, $beep_len)
        Sleep($sleep)
    next
    if $and_down = 1 then 
        for $i = $beeps to $bottom step - $step
            Beep($scaler * $i, $beep_len)
            Sleep($sleep)
        next
    endif
next

Check the full source for details on the parameters. It's probably over the top for your needs, but it would be trivial to rip it off and use it in your beeper, and is fun.

Another suggestion; the part of your code where it checks for command-line parameters is stuffed with code that could better be replaced with DoAboutBoxFunction(), the code being moved inside DoAboutBoxFunction() which would live elsewhere, maybe at the bottom.

Comments making up half the script is a good thing.

There can never be enough comments, so long as they aren't just *beep*.

;o)

(or


nothing is foolproof to the sufficiently talented fool..

Share this post


Link to post
Share on other sites

ah ok ya thanks for clearing that up i use them some times but usually i just use IF's unless i have a lot of stuff..

actually now that you mention it i probably should change it to just emit a single beep.. maybe 500hz for a quarter second or something.

originally it was suppose to just play a list of tones found in a file and thats it.. then i added it so you could call it to play a single tone..

currently if you dont tell it to emit a single sound.. or dont tell it to play a list in a file, then it looks for the file "beep" with no extension in the same directory.. if it's not found it just exits.

i had thought about functions.. but most of the stuff is only used once it's not very large or complex so figured making functions would be pointless.. since the script does pretty much everything i intended only thing could really be done is code and clean up, since functionally im not sure how i could improve a script that just emits beeps.

everytime i look at it i find areas i could have done better.. but im still learning all the commands.. i remember using v2 and it was simple i had been putting off learning v3 for a long time but im esp interested in the network functions and it's nice to see people doing all kinds of very complex things with autoit.

anyway, heres an example of what the files should look like:

1000,50,10
500,125,50
250,125,50
500,125,500

spaces are ok, however there must be 3 variables on every line seperated by "," .. if there is'nt the script will just exit rather then trying to cover up the error, this includes blank lines.

tone, duration, wait (time after tone is played before playing next one)

even if you do not want any wait you still have to include it ",0"

originally i just had it read the file as it played but it sometimes had shuddering, thought loading the file into arrays would fix it but as it turns out it still shudders sometimes.. i think it is the way it accesses the speaker IRQ's maybe?.. have you noticed this and if find a way to eliminate it?

actually i seen your clock it's pretty impressive most of my gui scripts so far are fairly simple it seems like the gui takes up a huge amount of lines and code.. none of my scripts are very big but gui if it has one is taking up at least as many lines.

although i had a problem opening some things.. like the color picker i get an array error. but it's still pretty impressive at some point i'll thumb thru it cause i esp like the menu on the system tray.

Share this post


Link to post
Share on other sites

I put up another update for cpc today, so check it out again, fo sho! I'll get it working on all systems yet, but like you say, gui stuff is more complex, at least, there's more that can go wrong when dealing with "other" machines. Without outside help, yer screwed.

Whether or not your script can be improved or not is probably more a philosophical question, I usually have a kind of zen approach to programming, trying to make programs, no matter how small or mundane they are, the best they can be. Having it play something when no command line parameters are present is the first thing I thought of, but there are more. The idea of moving that code to a function is mainly a question of readability; sure there's no speed improvements, and the code isn't re-used, but there are adavantages to a modularized approach, even to simple code.

With the code in a function, the CmdLine section becomes simply that; in future it's easier to understand it, update it, improve it, and so on, and the same story for the code that was moved out. It's only a beep, yes, but as you are just beginning with AutoIt 3, which is a world apart from AutoIt2, really, it's a great time to start good habits! Later, you might want to re-use the command-line part of your code, and you will have something relatively self-contained that you can just pick up and use.

Here's another small improvement, which also incorporates my first suggestion, replace..

If FileExists($file) = 0 Then exitoÝ÷ Û­«­¢+Ù¥¹½Ð¥±á¥ÍÑÌ ÀÌØí¥±¤Ñ¡¸($ÀÌØí¥±ôÅÕ½ÐíÁÌÅÕ½Ðì(%¥±]É¥Ñ1¥¹ ÀÌØí¥±°ÅÕ½ÐìÄÀÀÀ°ÔÀ°ÄÀÅÕ½ÐìµÀì
I1¤)¹¥

Or something like that.

l*rz..

;o)

(or

ps. switches rock; I find myself using them (and select) more and more, even when there are only one or two conditions.

pps. running with the zen theme; it's definitely wise to meditate on the term: Function.


nothing is foolproof to the sufficiently talented fool..

Share this post


Link to post
Share on other sites

aye, actually that line it self only needs to do that one thing, the variable it's to change already has a value..

but um.. ya i think i can actually save a little bit by combining in with some other cmd checks.. although i'd still like to know if it's possible to get that all onto one line or not without duplicating the first condition into the 2nd if anyone has any ideas.

The corrected line for #2 that I posted in my last reply should do it on 1 line but I don't recommend doing it that way.

Also note that in the last nested If example that I used

== "R"

and

== "r"

That was just to make them case sensitive allowing you to use the same letter twice. That can also be done in a Switch statement.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

actually i seen your clock it's pretty impressive most of my gui scripts so far are fairly simple it seems like the gui takes up a huge amount of lines and code.. none of my scripts are very big but gui if it has one is taking up at least as many lines.

corz is correct that proper manipulation of a Switch will cut down on the size of the GUI code. I just takes practice.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
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
Sign in to follow this  
Followers 0