Jump to content
SugarBall

How to write 2 IFs and to create action after?

Recommended Posts

SugarBall

Hey can anyone help me with the right syntax of writing 2 IF conditionals before completing an action? (two IFs must be completed so the action be performed)

should i write it " If(....) and If(......) then " or " If(....)  , If(....) then " or these are wrong ways? 

 

SugarBall

Share this post


Link to post
Share on other sites
mikell

One If, use "and" for the expressions

If ($a > $b) and ($c > $d) then

Look in the helpfile 'Operators'

  • Like 1

Share this post


Link to post
Share on other sites
Melba23

SugarBall,

Neither of those - this is the correct syntax:

If (....) And (......) Then

M23

  • Like 1

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

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
SugarBall

I thank you very much both mikell and Melba23

Share this post


Link to post
Share on other sites
ViciousXUSMC

Also Nested Statements can be the answer depending on your needs.

;Testing that X > 3 AND X < 10 both must be true

$X = InputBox("Value for X", "Please Enter Your Value for $X", 7)

If $X > 3 Then
If $X < 10 Then
MsgBox(0, "", "X is > 3 and < 10")
Else
MsgBox(0, "", "X is not < 10")
EndIf
Else
MsgBox(0, "", "X is Not > 3")
EndIf

The Else is completely optional, gives you a good way to return a value if false. 

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

  • Similar Content

    • WoodGrain
      By WoodGrain
      Hi guys,
      I'm learning about GUI's, I'm trying the below code, the idea being if I press the letter "e" while I have the GUI open I want the label color to change to green (I'm using a UDF for label colors). But every time I press "e" on my keyboard I just get a "ding" sound from my speakers and nothing changes with the label.
      I've looked at using something like "While GUIGetMsg() <> $GUI_EVENT_CLOSE" as I've seen it in other code instead of "While 1", but I don't think it's relevant.
      #include <GUIConstantsEx.au3>; for GUI... #include <GUIRichLabel.au3>; UDF for rich text label fonts #include <Misc.au3>; for _IsPressed $myLetter = "e" $hGUI = GUICreate("test", 700, 60) $lbl2 = _GUICtrlRichLabel_Create($hGUI, '<font color="purple">' & $myLetter & '</font>', 10, 10); , 260, 25 GUISetState(@SW_SHOW) Local $hDLL = DllOpen("user32.dll") While 1 if _IsPressed(Hex($myLetter), $hDLL) Then While _IsPressed(Hex($myLetter), $hDLL) Sleep(250) WEnd _GUICtrlRichLabel_SetData($lbl2, '<font color="green">' & $myLetter & '</font>') Sleep(2000) DllClose($hDLL) Exit EndIf Sleep(50) WEnd DllClose($hDLL) I am using an array of letters that I'm wanting to do this for, but as I can't get it to work I've stripped it down to the simplest code I can think of to try and get this working first. Appreciate any help.
      Thanks!
    • AndreasNWWWWW
      By AndreasNWWWWW
      Hi, i'm curious if this is even possible, i want to do an action if the ini file contains current values under a section.
      for my test i'm looking for 100,200,300,400,500
      and if any of those excits i want to pop a msgbox with the number in the section.
      i can in my example find one, but it does not check everyone. why?  what am i missing?
      Local $iscore810[5] = [100,200,300,400,500] Local $iMax800 = 5 While 1 ;~     Send("{pause}") ;;func les ini fil     $var = IniReadSection("Area.ini", "modus")     If @error Then         MsgBox(4096, "Error", "Unable to read section.")     Else          For $number = 1 To $var[0][0] If $var[$number][1] == $iscore810[3] Then       MsgBox($MB_SYSTEMMODAL, "FAnt den på", $var[$number][0], 5) EndIf                       Next     EndIf     exit WEnd  
    • Aleksandar
      By Aleksandar
      So can anyone help me ? I need to restart program when condition is not met ...

    • Gaffgarion
      By Gaffgarion
      i found this script by melba23 and its exactly what i wanted > link
      #include <Misc.au3> #include <MsgBoxConstants.au3> Local $hDLL = DllOpen("user32.dll") HotKeySet("{q}","_Start") ; Fire HotKey on q key HotKeySet("{ESC}", "_Exit") While 1 Sleep(10) WEnd Func _Start () ; Look for w key If _IsPressed("57", $hDLL) Then ; Only action if BOTH pressed MsgBox($MB_SYSTEMMODAL, "", "Got it") EndIf EndFunc Func _Exit() DllClose($hDLL) Exit EndFunc  
      if im not wrong, if i hold q key first and then press w key, then the output will be messagebox that says "got it"
      but when i tested it, it doesnt do anything.
      but if i reverse the order, hold w key first, and then press q key, it works.
      now i dont know why is this happen, or is this how this script supposed to do? or there's something wrong?
      thank you.
       
    • Eli_jahbot
      By Eli_jahbot
      my esteemed autoits,
      i need your help once again. The bold and italics below are what i will be referring to. I need a message box to exit the script if Cancel is pressed and to continue the script if OK is pressed. I have tried multiple ways to do this to no avail. Can someone please breakdown how i go about this via Message box, and or Input box as I'm sure they will follow the same logic. I appreciate your time and assistance.
       
      Example:
      global $url, $username, $password, $sspassword
      $url = "https://securegateway.fairview.org"
      $username = "XXX"
      $password = "YYY"
      $sspassword = "ZZZ"
      #include <Constants.au3>
      #include <msgboxconstants.au3>
      ShellExecute ($url)
      WinWaitActive("window")
      send($username)
      send("{tab}")
      send($password)
      send("{enter}")
      msgbox($mb_okcancel, "Wait for the page to load then select OK to continue script", "Wait for the page to load then select OK to continue script")
      if($idok)
      send("+{tab 8}")
      send("{enter}")
      if ($idcancel) then Exit
      EndIf
×