Jump to content

if and then not working correctly.. Need some help... Please...


bb01
 Share

Recommended Posts

Ok i know i'm doing something wrong for the error windows not to close..

What the script is meant to do, is grab the number form excel, then input into n-focus, if the number is incorrect it'll cause an error in nfocus therefore the _Errorscript() of the script should show...

then theres another error section (_Warning1scriptloop()) latter on in the script, when its picking a subject, if the subject does not exist, then it errors.. again this section does not work...

The whole script works perfectly except the error sections... which i cannot seem to work out why...

WinActivate("N-FOCUS - Search for Master Case - \\Remote, 256-bit SSL/TLS.", "")
WinWaitActivate2("N-FOCUS - Search for Master Case - \\Remote, 256-bit SSL/TLS.", "")

WinActivate("Microsoft Excel", "")
WinWaitActivate2("Microsoft Excel", "")
Send("{HOME}")
Send("{TAB}{CTRLDOWN}c{CTRLUP}")
WinActivate("N-FOCUS - Search for Master Case - \\Remote, 256-bit SSL/TLS.", "")
WinWaitActivate2("N-FOCUS - Search for Master Case - \\Remote, 256-bit SSL/TLS.", "")
Send("{DEL}")
Send("{CTRLDOWN}v{CTRLUP}{ENTER}")

If WinExists("N-FOCUS - Error - \\Remote, 256-bit SSL/TLS.","") Then
_Errorscript()
Else
_scriptloopPT1()
EndIf

Func _scriptloopPT1()
WinWaitActivate2("N-FOCUS - Detail Master Case - \\Remote, 256-bit SSL/TLS.", "")
Send("{ALTDOWN}gn{ALTUP}")
Sleep(10)
WinWaitActivate2("N-FOCUS - Search Narrative - \\Remote, 256-bit SSL/TLS.", "")
Sleep(10)
Send("{RIGHT}")
Sleep(30)
Send("{tab}")
Sleep(30)
Send("{SPACE}")
Sleep(30)
Send("{tab 3}")
Sleep(30)
Send("{DOWN 4}")
Sleep(30)
Send("{SPACE}")
Sleep(30)
Send("{ALTDOWN}o{ALTUP}")
  If WinExists("N-FOCUS - Error - \\Remote, 256-bit SSL/TLS.","") Then
  _Warning1scriptloop()
Else
  _Continuescriptloop2()
EndIf
EndFunc

; Contiuescript2 loop
Func _Continuescriptloop2()
WinActivate("Microsoft Excel", "")
WinWaitActivate2("Microsoft Excel", "")
Send("{HOME}{TAB 8}{CTRLDOWN}c{CTRLUP}")
Send("{HOME}{TAB 8}{CTRLDOWN}c{CTRLUP}")
Send("{HOME}{TAB 8}{CTRLDOWN}c{CTRLUP}")
WinWaitActivate2("N-FOCUS - Detail Narrative - \\Remote, 256-bit SSL/TLS.", "")
Send("{DOWN}{DOWN}{DOWN}{DOWN}{SPACE}")
WinWaitActivate2("N-FOCUS - Additional Narrative Detail - \\Remote, 256-bit SSL/TLS.", "")
WinActivate("N-FOCUS - Additional Narrative Detail - \\Remote, 256-bit SSL/TLS.", "")
WinWaitActivate2("N-FOCUS - Additional Narrative Detail - \\Remote, 256-bit SSL/TLS.", "")
Send("{CTRLDOWN}v{CTRLUP}{TAB}{ENTER}")
WinWaitActivate2("N-FOCUS - Detail Narrative - \\Remote, 256-bit SSL/TLS.", "")
Send("{ALTDOWN}fa{ALTUP}")
WinWaitActivate2("N-FOCUS - Search Narrative - \\Remote, 256-bit SSL/TLS.", "")
Send("{CTRLDOWN}c{CTRLUP}{ALTDOWN}c{ALTUP}")
WinWaitActivate2("N-FOCUS - Detail Master Case - \\Remote, 256-bit SSL/TLS.", "")
Send("{ALTDOWN}fc{ALTUP}")
WinWaitActivate2("N-FOCUS - Search for Master Case - \\Remote, 256-bit SSL/TLS.", "")
WinActivate("Microsoft Excel", "")
WinWaitActivate2("Microsoft Excel", "")
Send("{HOME}{DOWN}")
ShellExecute(@ScriptDir & "\loop2-New.exe")
Exit
EndFunc   ;==>_Continuescriptloop
Exit

Func _Warning1scriptloop()
_WinWaitActivate2("N-FOCUS - Error - \\Remote, 256-bit SSL/TLS.","")
MouseClick("left",275,90,1)
WinWaitActivate2("N-FOCUS - Search Narrative - \\Remote, 256-bit SSL/TLS.","")
Send("{ALTDOWN}F4{ALTUP}")
  _scriptloopPT1()
EndFunc   ;==>WinWaitActivate2

Func WinWaitActivate2($title, $text, $timeout = 0)
WinWait($title, $text, $timeout)
If Not WinActive($title, $text) Then WinActivate($title, $text)
WinWaitActive($title, $text, $timeout)
EndFunc   ;==>WinWaitActivate2

;----------- Error Script
Func _Errorscript()
WinActivate("Microsoft Excel", "")
WinWaitActivate2("Microsoft Excel", "")
Send("{HOME}")
Send("{TAB 9}")
Send("Not Imput Due To Error")
Send("{HOME}{DOWN}")
WinActivate("Error - \\Remote, 256-bit SSL/TLS.", "")
WinWaitActivate2("Error - \\Remote, 256-bit SSL/TLS.", "")
Send("{ENTER}")
ShellExecute(@ScriptDir & "\loop2-New.exe")
Exit
EndFunc   ;==>_Errorscript

;------------ _Terminate()
Func _Terminate()
WinSetState("N-FOCUS - Search for Master Case - \\Remote, 256-bit SSL/TLS.", "", @SW_MINIMIZE)
MsgBox(0, "Script Is Finished", "Finished" & _
   @CRLF & @CRLF & " The Script Is Now Finished " & _
   @CRLF & " It'll Shut Down Excel" & _
   @CRLF & "And Then Close This Script && Open" & _
   @CRLF & "Up The Script Loader For You", 60)
WinClose("Microsoft Excel")
Exit
EndFunc   ;==>_Terminate

Thanks in advance guys...

Link to comment
Share on other sites

It might be easier to use the Excel.au3 UDF to automate working with Excel rather than reading data from the windows and hoping you get the right sheet etc.

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

Try copy/paste the actual windows title content directly from the AutoIt Info tool. Some programs use unexpected invisible characters there (like non-breaking space, or wide space & al.) In this case a regular space won't match.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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