Jump to content

Help formatting simple "if" logic


Go to solution Solved by hiho,

Recommended Posts

Hi,

 
If $aLine[2] = "" or
   $aLine[2] = "Ingen" or
   $aLine[2] = "//www.powertech.no/cgi-bin/mailform" or
   $aLine[2] = "Send" or
   $aLine[2] = "none" or 
   $aLine[2] = "off" Then _ArrayDelete($aBody, $i)

 The above code gives me error ""If" statements must have a "Then" keyword.". Whereas if I type it on a single line..:
 

If $aLine[2] = "" or $aLine[2] = "Ingen" or $aLine[2] = "//www.powertech.no/cgi-bin/mailform" or $aLine[2] = "Send" or $aLine[2] = "none" or $aLine[2] = "off" Then _ArrayDelete($aBody, $i)

 
..it works perfectly fine. This is just an aesthetic issue, but it's much easier to work with the formatting in case 1 since I'll be adding a lot of "or's".

What's the best way to go about this?

Link to comment
Share on other sites

Thanks, that underscore solved a lot of problems!
 
About Switch I'm not so sure since I think I would have to state " _ArrayDelete($aBody, $i)" for every case which would be kinda tiresome. e.g:
 

Switch $aLine[2]
    Case """"
        _ArrayDelete($aBody, $i)
    Case "Ingen"
        _ArrayDelete($aBody, $i)
    Case "Send"
        _ArrayDelete($aBody, $i)
;etc. etc.
EndSwitch

..or am I just using Switch wrong?

Link to comment
Share on other sites

Switch $aLine[2]
    Case """", "Ingen", "Send"
        _ArrayDelete($aBody, $i)
;etc. etc.
EndSwitch

You can put multiple tests on a Case statement for Switch, separated by commas. As long as they all are going to do the same thing if matched, you can do it all on one line.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Cool. But since I am going for an organized structure I'd prefer having everything on separated lines. So I might aswell go for "if" with underscores:

If $aLine[2] = "" or _
   $aLine[2] = "Ingen" or _
   $aLine[2] = "//www.powertech.no/cgi-bin/mailform" or _
   $aLine[2] = "Send" or _
   $aLine[2] = "none" or _
   $aLine[2] = "off" Then _ArrayDelete($aBody, $i)

I'm just trying to evaluate why somdcomputerguy said it would be better to use "switch".

Link to comment
Share on other sites

Switch is usually faster than If statements. You can put everything on one line without a lot of Ors.

EDIT: You can also use the continuation character in the case statement of a switch.

Switch $aLine[2]
    Case """", _
            "Ingen", _
            "Send"
        _ArrayDelete($aBody, $i)
        ;etc. etc.
EndSwitch
Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Ah yes you are correct, now I see. By using switch in this case I save typing "$aLine[2] =" for every condition. And when using continuation characters I can get everything on separated lines as well for nice clean structure.Thanks!  :thumbsup:

Sack

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