Jump to content
Jonboy

If Else Statements

Recommended Posts

Jonboy

Can someone help me out with this. I for the life of me don't have any idea why this if then else statement won't work.

   local $hWnd
$hWnd = WinWaitActive("[TITLE:New Session Wizard; CLASS:#32770;]")
    If (WinGetTitle($hWnd) == "New Session Wizard")Then
  SessionWizzard() ; functions that go through the new session wizard this is define elsewhere in my script.
    Else                     ; Thing is this will run correctly the 1st time but after the 1st time it will not switch over to the else statement.
    $hWnD = WinWaitActive("[TITLE:Connect; CLASS:#32770;]")
    If(WinGetTitle($hWnd)=="Connect") Then
      Sleep(100)
      send("{ENTER}")
    EndIf
  EndIf

 

 

Share this post


Link to post
Share on other sites
BrewManNH

There's not enough of your script to identify an issue.

Although, $hWnd will not have a handle in it if the window title doesn't exist, so the first part of the If statement will not work, and it should go to the Else because the window doesn't exist.

This section is pointless because you would already know that the title equals Connect at that point because your WinWaitActive won't proceed if it can't find a window with that title.

If (WinGetTitle($hWnd) == "Connect") Then ; <<<<<<<<<<<<<<<<<<<
        Sleep(100)
        Send("{ENTER}")
    EndIf ; <<<<<<<<<<<<<<<<<<<<

Maybe explain where it's failing with better code that runs?


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

Share this post


Link to post
Share on other sites
Jonboy

Remove the unnecessary part, again thanks for the help completely new to AutoIT.

Global Const $CLIENT_EXECUTABLE                                 = "filepath\qws3270s.exe" ; CHANGE_ME - change if installed in different path
Global Const $DISPATCHER_NAME                                   = "QWS_Dispatcher"
Global $TargetUsername = "UserID"
Global $TargetPassword = "SuperSecretPassword"
Global $sleep = 100
AutoItSetOption("WinTitleMatchMode", 3)

; Run exe and activate
      Local $ConnectionClientPID = Run($CLIENT_EXECUTABLE, "", @SW_MAXIMIZE)
    if ($ConnectionClientPID == 0) Then
        ;Error(StringFormat("Failed to execute process [%s]", $CLIENT_EXECUTABLE, @error))
    EndIf

   local $hWnd = WinWaitActive("[TITLE:New Session Wizard; CLASS:#32770]")
  If(WinGetTitle($hWnd)=="New Session Wizard") Then
  SessionWizzard()
  Else
         Sleep(100)
         send("{ENTER}")

   EndIf



;#Acutal Login process=============================================================================================================

$hWnD = WinWaitActive("[TITLE:1.1.1.1; CLASS:QWS3270S;]")
if(WinGetTitle($hWnD) == "1.1.1.1")Then

   Sleep(1000)
   ;Username
   Sleep(1000)
   Send($TargetUsername)

    ;Password
    sleep(100)
    Send($TargetPassword)

    ;send Enter
    sleep(100)
    Send("{ENTER}")
EndIf


Func SessionWizzard()
      Sleep(100)
      Send("{tab}")
      Send("{tab}")
      Sleep(100)
      Send("{ENTER}")
      Sleep(100)
      send($address)
      sleep(100)
      Send("{TAB}")
      Send("{TAB}")
      sleep(100)
      send("{ENTER}")
       Send("{TAB}")
      Send("{TAB}")
      sleep(100)
      send("{ENTER}")
       Send("{TAB}")
      Send("{TAB}")
      sleep(100)
      send("{ENTER}")
      Send($address)
      Send("{TAB}")
      Send("{TAB}")
      send("{ENTER}")
      send("{ENTER}")
   Local $hWnD = WinWaitActive("[TITLE:Connect; CLASS:#32770]")
   If(WinGetTitle($hWnd)=="Connect") Then
         Sleep(100)
         send("{ENTER}")
         EndIf

EndFunc

 

Share this post


Link to post
Share on other sites
BrewManNH

I just realized that this will only ever work if the title of the window is "New Session Wizard" because of the WinWaitActive here.

local $hWnd = WinWaitActive("[TITLE:New Session Wizard; CLASS:#32770]")
  If(WinGetTitle($hWnd)=="New Session Wizard") Then
  SessionWizzard()
  Else
         Sleep(100)
         send("{ENTER}")

   EndIf

WinWaitActive won't proceed until the window title matches what you have in there. So, your whole script grinds to a halt as soon as the title changes. Try this to get the title of the window of the program you started.

#include <WinAPIProc.au3> ; <<<<<<<<<<<<<<<<<<<<<<<< Add thisline

Local $ConnectionClientPID = Run($CLIENT_EXECUTABLE, "", @SW_MAXIMIZE)
If ($ConnectionClientPID == 0) Then
    ;Error(StringFormat("Failed to execute process [%s]", $CLIENT_EXECUTABLE, @error))
EndIf

Local $aWnd = _WinAPI_EnumProcessWindows($ConnectionClientPID) ; <<<<<<<<<<<<<<<<< Gets the windows handle of the process  you started above
If (WinGetTitle($aWnd[1][0]) = "New Session Wizard") Then ; <<<<<<<<<<<<< Checks the title of the window
    SessionWizzard()
Else
    Sleep(100)
    Send("{ENTER}")

EndIf

 


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

Share this post


Link to post
Share on other sites
Jonboy

Updated code and got the following error.

image.png.4434e502686c95418ebaf503890fc101.png

Share this post


Link to post
Share on other sites
BrewManNH

That means the program never started, and your If/Endif statement above should be able to catch that, but does nothing. Your script should either exit if the PID is zero, or retry running the program until the PID > 0


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

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

×