enigmafyv Posted January 13, 2007 Posted January 13, 2007 I'm running and installation of a program, and it requires to connect to a database server. Well sometimes when I enter the IP address of the server, it comes back saying 'Unable To Connect', other times it goes through. If it doesn't connect using the IP address, then I usually change the IP address to the DNS server name. Here's the tricky part (for me). Note: %WinTitle% is my own generic label to represent the "Windows Title" I would like to be able to monitor whether the %WinTitle% is "Unable To Connect" or "%ProgramName%". Here's the code: Do $title = WinGetTitle("", "") Sleep(100) Until $title = "Unable To Connect" If $title = "Unable To Connect" Then WinWaitActive("Unable To Connect", "") ControlClick("Unable To Connect", "", "Button1") WinWaitActive("Specify Database Server", "") If Not WinActive("Specify Database Server","") Then WinActivate("Specify Database Server","") WinWaitActive("Specify Database Server","") MsgBox(0,"Turn on network", "Turn on your network connection now please.") ControlSetText("Specify Database Server", "", "Edit1", "%ServerName%") ControlClick("Specify Database Server", "", "Button2") Else If WinActive("%ProgramName%", "") Then $Satis = ControlGetText("%ProgramName%", "", "Button1") If $Satis = "&Finish >" Then WinActivate("%ProgramName%", "") ControlClick("%ProgramName%", "", "Button1") Else MsgBox(0, "Attention", 'Please click the Finish button.') EndIf EndIf The problem with this code is, if the %WinTitle% never goes to "Unable To Connect" it's stuck in an infinite loop. So I would like it to check every Sleep(100) seconds (10th of a second) for the name of the windows title, if it's "Unable To Connect" do x, if it's "%ProgramName%" do y. To be even simpler: Do 1 if x, if 1 fails do 2, Else do A if y. I hope this makes sense. Can someone help pls? TIA
Outshynd Posted January 13, 2007 Posted January 13, 2007 (edited) Until $title = "Unable to connect" Or $title = "%Program Name%" Then let your if..else statement handle what to do. Edited January 13, 2007 by Outshynd
Uten Posted January 13, 2007 Posted January 13, 2007 (edited) Do $title = WinGetTitle("", "") If $title = "Title1" Then ExitLoop ElseIf $title = "Title2" Then ExitLoop Else Sleep(100) EndIf Until GuiGetMsg = -3 ;$GUI_EVENT_CLOSE You could asloe use the regexp option in WinWait("regexp=" & $title1" & "|" & $title2) PS: The syntax could be wrong so look it up in the help file. You have to search for regexp. EDIT: Darn to late.. Nice solution in previous post! Edited January 13, 2007 by Uten Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
Paulie Posted January 13, 2007 Posted January 13, 2007 Until $title = "Unable to connect" Or "%Program Name%"oÝ÷ Ù8^WÊ«÷¥±ë-jצz{ajwe{Z¶Ú£ú®¢×¢ØZL(mv!jØ^Á©í±8Z· .×h¶rبÊÞªÝë,¡ü!Èh~Ø^ÙÊ'v+b¢{"²Úîz°j{l²¶§Ø}êÞ×èæÊ'v+b¢tëÊØb±«¢+Ø)MÝ¥Ñ ÀÌØíѥѱ( ÍÅÕ½ÐíU¹±Ñ¼½¹¹ÐÅÕ½Ðì(í¼M½µÑ¡¥¹( ÍÅÕ½ÐìAɽɴ9µÅÕ½Ðì(í¼M½µÑ¡¥¹±Í)¹MÝ¥Ñ (
MHz Posted January 13, 2007 Posted January 13, 2007 You could asloe use the regexp option in WinWait("regexp=" & $title1" & "|" & $title2)Opt('WinTitleMatchMode', 4) Run('Notepad') WinWait('regexp=Untitled|Titled') If WinExists('Untitled') Then WinActivate('Untitled') WinWaitActive('Untitled') MsgBox(0, 'Untitled', 'Done') Else WinActivate('Titled') WinWaitActive('Titled') MsgBox(0, 'Titled', 'Done') EndIf
Outshynd Posted January 13, 2007 Posted January 13, 2007 No, thank won't do what he wants, That would do the actions regardless of which of the 2 conditions is true, he wants something different for each condition Try this: Switch $title Case "Unable to connect" ;Do Something Case "%Program Name%" ;Do Something Else EndSwitch oÝ÷ Ûú®¢×¢Øb³ .Ù÷öÜ(®F®¶sdFð¢·6öÖWFæp¥VçFÂb33c¶Ò÷"b33c¶Ò ¤bb33c¶ÒFVࢷ6öÖWFæp¤VÇ6Tbb33c¶Ò"FVࢷ6öÖWFærVÇ6P¤VæD` That's basically what he has. It would require changing very little of his script. It's not the best way of doing it, sure, but it requires changing very little.
Uten Posted January 13, 2007 Posted January 13, 2007 The Do ;something Until $a = 1 Or $a = 2 If $a = 1 Then ;something ElseIf $a = 2 Then ;something else EndIfis good because most people can relate to it. The WinWait('regexp=' & $title1 & "|" & $title2) Is better because it will not waste resources. But it require a bit more understanding than TP seems to have at the moment. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
enigmafyv Posted January 15, 2007 Author Posted January 15, 2007 I just want to thank everyone for responding with all the different techniques. I haven't tried any yet, but I will here soon. I'll give them all a try to see how well each works for my situation. Thanks again.
Paulie Posted January 16, 2007 Posted January 16, 2007 So, this wouldn't work? Do ;something Until $a = 1 Or $a = 2 If $a = 1 Then ;something ElseIf $a = 2 Then ;something else EndIf That's basically what he has. It would require changing very little of his script. It's not the best way of doing it, sure, but it requires changing very little.Sorry, I missed the suggestion you had for using an If...ElseIf...Endif That will work, That was my misunderstanding. Note though, that you can switch those if statments with one switch.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now